策略模式的出行旅游:
答案:1 悬赏:80 手机版
解决时间 2021-03-17 15:38
- 提问者网友:最爱你的唇
- 2021-03-16 17:05
策略模式的出行旅游:
最佳答案
- 五星知识达人网友:过活
- 2021-03-16 17:12
; }}class TrainStrategy implementsTravelStrategy{ public function travelAlgorithm(){ echotravelbyTrain,
; }}class BicycleStrategy implementsTravelStrategy{ public function travelAlgorithm(){ echotravelbyBicycle,
; }}class PersonContext{ private$_strategy = null; public function __construct(TravelStrategy$travel){ $this->_strategy=$travel; } public functionset TravelStrategy(TravelStrategy$travel){ $this->_strategy=$travel; } public function travel(){ return$this->_strategy->travelAlgorithm(); }}//乘坐火车旅行$person=newPersonContext(newTrainStrategy());$person->travel();//改骑自行车$person->setTravelStrategy(newBicycleStrategy());$person->travel();?>
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯