<?php public function makeReservation($mainkey){ $type = getReservationTypeByMainkey($mainkey); switch($type):{ case 'A': $this->reservationAConfig($mainkey); break; case 'B': $this->reservationBConfig($mainkey); break; ..... } } private function reservationAConfig($mainkey){ //这里进行A配置的预约逻辑操作 } private function reservationBConfig($mainkey){ //这里进行B配置的预约逻辑操作 } private function getReservationTypeByMainkey($mainkey){ //根据预约号获取预约配置的类型 } <?php interface ReservationStrategy { //执行预约配置逻辑操作 public function makeReservation(); } //策略处理类 class ReservationHandler { private $strategy = null; public function __construct(ReservationStrategy $strategy){ $this->$strategy = $strategy; } //封装了策略执行的逻辑,所有执行的预约配置统一调用这个方法 public function makeReservation(){ $this->$strategy->makeReservation(); } } //A配置的具体策略类 class AReservationStrategy implements ReservationStrategy { public function makeReservation(){ //这里执行A配置的逻辑操作 ; } class ReservationFacaory { public static function getReservationInstance($mainkey){ //这里可以根据预约号做具体逻辑生成策略对象 } } //预约控制器代码 class ReservationController { public function makeReservation($mainkey){ //根据工厂对象创建预约策略实例 $reservation = ReservationFacaory::getReservationInstance($mainkey); //传入实例给策略处理类 $handler = new ReservationHandler($reservation); //执行预约策略 $handler->makeReservation(); } } Wooden Speakers https://www.zeshuiplatform.com/