简单工厂模式
//---------------------------------------------------
//进去参数(类名),出来直接就是对象,没有其他的步骤 //电影介绍的处理类 class MovieViews { public function getTimes() { //返回电影介绍的浏览次数 return 100; } } //电影种子下载的处理类 class MovieBtDowns { public function getTimes() { //返回电影种子的下载次数 return 18; } } //电影工厂 class MovieFactory { //获取电影处理类的对象,参数为类名 public function getMovieObject($className) { return new $className; } } //获取电影工厂 $movieFactory = new MovieFactory(); //电影介绍 $what = 'MovieViews'; $movieObject = $movieFactory->getMovieObject($what); echo $movieObject->getTimes(); //电影种子下载 $what = 'MovieBtDowns'; $movieObject = $movieFactory->getMovieObject($what); echo $movieObject->getTimes(); ?>