标签:end OGGS fun data new 创建者 抽象 app 简单工厂
代码示例:
//产品抽象基类 abstract class ApptEncoder { abstract public function encode(); } //产品子类1 class BloggsApptEncoder extends ApptEncoder { public function encode() { return "Appointment data encode in BloggsCal format\n"; } } //产品子类2 class MegaApptEncoder extends ApptEncoder { public function encode() { return "Appointment data encode in MegaCal format\n"; } } //创建者 class CommsManager { public function getApptEncoder($type) { switch($type) { case ‘Bloggs‘: return new BloggsApptEncoder(); case ‘Mega‘: return new MegaApptEncoder(); } } } $manager = new CommsManager(); //生成产品子类1对象 $encoder1 = $manager->getApptEncoder(‘Bloggs‘); echo $encoder1->encode(); //生成产品子类2对象 $encoder2 = $manager->getApptEncoder(‘Mega‘); echo $encoder2->encode();
标签:end OGGS fun data new 创建者 抽象 app 简单工厂
原文地址:https://www.cnblogs.com/wujuntian/p/9622779.html