策略模式
<?php //策略模式 interface OrderPayInterface { public function PayEvent($OrderId = null); } class OrderPay implements OrderPayInterface { public function PayEvent($OrderId = null) { echo "订单ID为:{$OrderId}的订单状态为已支付" . PHP_EOL; } } abstract class OrderEventAbstract { private $Observer; public function register(OrderPayInterface $pay) { $this->Observer = $pay; } public function notify($OrderId) { $this->Observer->PayEvent($OrderId); } } class Order extends OrderEventAbstract { public function pay($OrderId) { echo "支付成功" . PHP_EOL; $this->notify($OrderId); } } $order = new Order(); $order->register(new OrderPay()); $order->pay(1);