2.策略模式和简单工厂结合
// 只需要修改上方的Context类
class Context
{
private $strategy;
function __construct($operation)
{
$this->strategy = new ConcreteStrategyA();
break;
case 'b':
$this->strategy = new ConcreteStrategyB();
break;
case 'c':
$this->strategy = new ConcreteStrategyC();
break;
public function contextInterface()
{
return $this->strategy->AlgorithmInterface();
}
}
//客户端代码
总结:
上一章: