//委託模式:類的一些功能交給其餘的類去作, //其實我也比較困惑,委託模式和裝飾器模式有什麼區別呢?區別在於數據結構是否改變 //策略模式呢。主要是不一樣的算法 //公司 class Company{ private $_delegate; public function setDelegate($delegate){ $this->_delegate = $delegate; } public function doSomeWork(){ echo "幹活更有勁"; } public function feedWorkerMoney(){ $this->_delegate->feedWorkerMoney(); $this->doSomeWork(); } } //外包財務公司 class FeedMoney { public function feedWorkerMoney(){ echo "發送獎金\n"; } } $c_obj = new Company(); $c_obj->setDelegate(new FeedMoney()); $c_obj->feedWorkerMoney();