欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

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();