예제 #1
0
    public function __get($key)
    {
        return $this->{$key};
    }
    public function gettype()
    {
        return $this->_type->gettype();
    }
    public function getname()
    {
        return $this->_type->getname($this);
    }
}
//应用
$man1 = new person("王路", new man());
echo $man1->gettype() . $man1->getname();
/*接口方式实现策略模式*/
interface travelstrategy
{
    public function traveltype();
}
//具体策略类
class airplane implements travelstrategy
{
    public function traveltype()
    {
        echo "坐飞机";
    }
}
//具体策略类
class bus implements travelstrategy