龙华做棋牌网站建设,学校网站如何建设,设计软件培训机构排行榜,网站建设费用估计Decorator(装饰器)模式能够像标准的继承一样为类添加新的功能。 不同于标准继承机制的是,如果对象进行了实例化,Decorator模式能够在运行时动态地为对象添加新的功能。 ?php
abstract class AbstractCar{public abstract function getPrice();public abstract function g…Decorator(装饰器)模式能够像标准的继承一样为类添加新的功能。 不同于标准继承机制的是,如果对象进行了实例化,Decorator模式能够在运行时动态地为对象添加新的功能。 ?php
abstract class AbstractCar{public abstract function getPrice();public abstract function getManufacturer();
}
class Car extends AbstractCar{private $price200000;private $manufacturerbmw;public function getPrice(){return $this-price;}public function getManufacturer(){return $this-manufacturer;}
}class CarDecorator extends AbstractCar{private $target;public function __construct(Car $target){$this-target$target;}public function getPrice(){return $this-target-getPrice();}public function getManufacturer(){return $this-target-getManufacturer();}
}class NavigationSystem extends CarDecorator{public function getPrice(){return parent::getPrice()1000;}
}$carnew Car();
$carnew NavigationSystem($car);echo $car-getPrice();? 转载于:https://www.cnblogs.com/HKUI/p/4357969.html