class Order
{
private $promotion;
public function __construct($promotion = null)
{
$this->promotion = $promotion;
}
public function due($price)
{
return $this->promotion->discount($price);
}
}
interface Promotion
{
public function discount($price);
}
/**
- 第一个策略 打8折
- Class First
*/
class First implements Promotion
{
public function discount($order){
return $order * 0.8;
}
}
/**
- 第一个策略 打6折
- Class First
*/
class Second implements Promotion
{
public function discount($order){
return $order * 0.6;
}
}
$first = new First();
o
r
d
e
r
=
n
e
w
O
r
d
e
r
(
order = new Order(
order=newOrder(first);
$price = $order->due(400);
echo $price;