php中的设计模式之策略模式
程序员文章站
2022-06-05 23:26:12
...
strategy = $strategy; } // 开始策略 public function startStrategy(){ $this->strategy->handle(); } }$people = 'teacher';switch($people){ case 'student' : $strategy = new studentStrategy () ;break; case 'teacher' : $strategy = new teacherStrategy () ;break;}$safePeople = new TestCheck();$safePeople ->setStrategy($strategy);$safePeople ->startStrategy();