策略模式
<?php //定义策略接口 interface Strategy{ public function getTrafic(); } //选择策略接口 //行走 class stepStrategy implements Strategy{ public function getTrafic(){ echo "i go step by step"; } } //自行车 class bikeStrategy implements Strategy{ public function getTrafic(){ echo "use bike trafic to somewhere"; } } //公共汽车 class busStrategy implements Strategy{ public function getTrafic(){ echo "why not use buses"; } } //客户端交通 class Trafic{ public function useTrafic($obj){ return $obj->getTrafic(); } } $trafics = new Trafic(); $trafics->useTrafic(new bikeStrategy()); ?>