如果上面的hello例子,又多出来表达方式,正常和歌唱式表达(2个产品族) 复制代码 代码如下: //抽象工厂 abstract class Speaker{ const NORMAL =1; const SING =2; abstract function assignSpeaker($flag_int); } //具体工厂1 class EnglishSpeaker extends Speaker { public function assignSpeaker($flag_int){ switch($flag_int){ case self::NORMAL: return new NormalEnglish(); break; case self::SING: return new SingEnglish(); break; } } } //具体工厂2 class ChineseSpeaker extends Speaker{ public function assignSpeaker($flag_int){ switch($flag_int){ case self::NORMAL: return new NormalChinese(); break; case self::SING: return new SingChinese(); break; } } } //抽象产品 interface Hello{ function say_hello(); } //具体产品A1 class NormalEnglish implements Hello{ public function say_hello(){ echo "Hello!"; } } //具体产品B1 class NormalChinese implements Hello{ public function say_hello(){ echo "你好!"; } } //具体产品A2 class SingEnglish implements Hello{ public function say_hello(){ echo "Oh, jingle bells, jingle bells, Hello! Hello! Hello!"; } } //具体产品B2 class SingChinese implements Hello{ public function say_hello(){ echo "叮叮当,叮叮当, 你好!你好!你好!"; } }