标签:public imp 模式 color 设计 ons on() php eol
<?php class Bulb { public function turnOn() { echo ‘Bulb has turned on‘; } public function turnOff() { echo ‘Bulb has turned off‘; } } interface Order { public function execute(); public function undo(); public function redo(); } class TurnOn implements Order { private $_bulb; public function __construct(Bulb $bulb) { $this->_bulb = $bulb; } public function execute() { $this->_bulb->turnOn(); } public function undo() { $this->_bulb->turnOff(); } public function redo() { $this->_bulb->turnOn(); } } class TurnOff implements Order { private $_bulb; public function __construct($bulb) { $this->_bulb = $bulb; } public function execute() { $this->_bulb->turnOff(); } public function undo() { $this->_bulb->turnOn(); } public function redo() { $this->_bulb->turnOff(); } } class Control { public function submit($order) { $order->execute(); } } $bulb = new Bulb(); $turnOn = new TurnOn($bulb); $turnOff = new TurnOff($bulb); $control = new Control(); $control->submit($turnOn); echo PHP_EOL; $control->submit($turnOff);
标签:public imp 模式 color 设计 ons on() php eol
原文地址:http://www.cnblogs.com/Bin-x/p/7203962.html