Permalink
Browse files

重構 5 式 : Extract Interface

  • Loading branch information...
1 parent c6071d3 commit 5f3b9ba391d95a443d38c246227c7db523206405 Sam.IO.Hsiao committed Nov 27, 2016
Showing with 21 additions and 9 deletions.
  1. +1 −1 app/Services/AbstractLogistics.php
  2. +12 −0 app/Services/LogisticsInterface.php
  3. +8 −8 app/Services/ShippingService.php
@@ -4,7 +4,7 @@
use Illuminate\Support\Collection;
-abstract class AbstractLogistics
+abstract class AbstractLogistics implements LogisticsInterface
{
/**
* @param array $weightArray
@@ -0,0 +1,12 @@
+<?php
+namespace App\Services;
+
+interface LogisticsInterface
+{
+ /**
+ * @param array $weightArray
+ * @param int $amount
+ * @return int
+ */
+ public function calculateFee(array $weightArray, int $amount) : int;
+}
@@ -16,23 +16,23 @@ public function calculateFee(array $weightArray, string $companyName): int
switch ($companyName) {
case 'BlackCat':
- $blackCat = new BlackCat();
- $amount = $blackCat->calculateFee($weightArray, $amount);
+ $logistics = new BlackCat();
+ $amount = $logistics->calculateFee($weightArray, $amount);
break;
case 'Hsinchu':
- $hsinchu = new Hsinchu();
- $amount = $hsinchu->calculateFee($weightArray, $amount);
+ $logistics = new Hsinchu();
+ $amount = $logistics->calculateFee($weightArray, $amount);
break;
case 'PostOffice':
- $post = new Post();
- $amount = $post->calculateFee($weightArray, $amount);
+ $logistics = new Post();
+ $amount = $logistics->calculateFee($weightArray, $amount);
break;
default:
- $blackCat = new BlackCat();
- $amount = $blackCat->calculateFee($weightArray, $amount);
+ $logistics = new BlackCat();
+ $amount = $logistics->calculateFee($weightArray, $amount);
break;
}

0 comments on commit 5f3b9ba

Please sign in to comment.