PHP设计模式-抽象工厂
interface technology{ public function top(); } interface humanity{ public function most(); } class american implements technology{ public function top(){ echo '芯片'; } } class chinese implements technology{ public function top(){ echo '5G'; } } class americanMan implements humanity{ public function most(){ echo '性情开朗、 乐于交际、 不拘礼节'; } } class chinaMan implements humanity{ public function most(){ echo '厚德开放与包容'; } } interface compareFactory{ public function compareTeco(); public function compareHumanity(); } class americanFactory implements compareFactory{ public function compareTeco(){ return new american(); } public function compareHumanity(){ return new americanMan(); } } class chineseFactory implements compareFactory{ public function compareTeco(){ return new chinese(); } public function compareHumanity(){ return new chinaMan(); } } $china = new chineseFactory(); $chinaTeco = $china->compareTeco(); $chinaTeco->top(); $chinaHumanty = $china->compareHumanity(); $chinaHumanty->most();
只是查找方便的总结