PHP设计模式-简单工厂模式
<?php class american{ public function talk(){ echo 'english'; } public function skin(){ echo 'while'; } } class chiness{ public function talk(){ echo '汉语汉语'; } public function skin(){ echo '黄色'; } } class controll{ public function anser($people){ switch($people){ case 'chiness': return new chiness(); case 'american': return new american(); default: return null; } } } $obj = new controll(); $chiness = $obj->anser('chiness'); $chiness->talk(); $chiness->skin(); ?>
只是查找方便的总结