php-设计模式-模板方法模式
2015-02-09 19:35
573 查看
abstract class Journey { final public function takeATrip() { $this->buyAFlight(); $this->takePlane(); $this->enjoyVacation();//!!! $this->buyGift(); $this->takePlane(); } //key feature abstract protected function enjoyVacation(); //optional. protected function buyGift() { } /** * This method will be unknown by subclasses (better) */ private function buyAFlight() { echo "Buying a flight\n"; } final protected function takePlane() { echo "Taking the plane\n"; } } class CityJourney extends Journey { protected function enjoyVacation() { echo "Eat, drink, take photos and sleep\n"; } } class BeachJourney extends Journey{ protected function enjoyVacation() { echo "Swimming and sun-bathing\n"; } } $journey = new BeachJourney(); $journey->takeATrip(); //Buying a flight //Taking the plane //Swimming and sun-bathing $journey = new CityJourney(); $journey->takeATrip();
相关文章推荐
- PHP设计模式-模板模式(模板方法模式)
- PHP设计模式-模板模式(模板方法模式)
- 设计模式入门-模板方法模式(php版)
- php实现设计模式之 模板方法模式
- Php设计模式之【模板方法模式Template Method Pattern 】
- PHP草根论之设计模式-模板方法模式
- 学习php设计模式 php实现模板方法模式
- 初识PHP设计模式--模板方法模式
- 模板方法模式(学习于 php设计模式 书 )
- PHP设计模式之模板方法模式定义与用法详解
- 学习php设计模式 php实现模板方法模式
- PHP设计模式系列(六):模板方法模式
- 设计模式之模板方法模式(Template Method)
- 设计模式学习之 模板方法模式
- 深入浅出Java模式设计之模板方法模式
- 设计模式--模板方法模式(照旧,有类关系图)
- 白话设计模式--行为型模式--Template Method模式(模板方法模式)
- 设计模式——模板方法模式(TemplateMethod)
- 更好的构造开发模板 五种常见的PHP设计模式
- 我读设计模式之模板方法模式(TemplateMethod Pattern)