Permalink
Browse files

ShoppingService重構成使用constructor injection

  • Loading branch information...
oomusou committed Apr 17, 2016
1 parent eb7a53f commit b3b66a2cbbe3276d833aa0c655420938da465ec3
Showing with 14 additions and 7 deletions.
  1. +14 −7 app/Services/ShippingService.php
@@ -2,19 +2,26 @@
namespace App\Services;
use Exception;
class ShippingService
{
/** @var LogisticsInterface */
private $logistics;
/**
* ShippingService constructor.
* @param LogisticsInterface $logistics
*/
public function __construct(LogisticsInterface $logistics)
{
$this->logistics = $logistics;
}
/**
* @param string $companyName
* @param int $weight
* @return int
* @throws Exception
*/
public function calculateFee($companyName, $weight)
public function calculateFee($weight)
{
$logistics = LogisticsFactory::create($companyName);
return $logistics->calculateFee($weight);
return $this->logistics->calculateFee($weight);
}
}

0 comments on commit b3b66a2

Please sign in to comment.