抽象工廠模式例項與講解
阿新 • • 發佈:2019-01-25
ApptEncoder{
abstract function encode();
}
class BloggsApptEncoder extends ApptEncoder{
function encode(){
return 'this is BloggsApptEncoder object';
}
}
class MegaApptEncoder extends ApptEncoder{
function encode(){
return 'this is MegaApptEncoder object';
}
}
abstract class ContactEncoder{
abstract function encode();
}
class BloggsContactEncoder extends ContactEncoder{
function encode(){
return 'this is BloggsContactEncoder object';
}
}
class MegaContactEncoder extends ContactEncoder{
function encode(){
return 'this is MegaContactEncoder object' ;
}
}
abstract class ContachEncoder{
abstract function encode();
}
class BloggsContachEncoder extends ContachEncoder{
function encode(){
return 'this is BloggsContachEncoder object';
}
}
class MegaContachEncoder extends ContachEncoder{
function encode(){
return 'this is MegaContachEncoder object' ;
}
}
abstract class TtdEncoder{
abstract function encode();
}
class BloggsTtdEncoder extends TtdEncoder{
function encode(){
return 'this is BloggsContactEncoder object';
}
}
class MegaTtdEncoder extends TtdEncoder{
function encode(){
return 'this is MegaApptContactEncoder object';
}
}
abstract class CommsManager{
const APPT = 1;
const TTD = 2;
const CONTACT = 3;
abstract function getHeaderText();
abstract function make($flat_int);
abstract function getFooterText();
}
class BloggsCommsManager extends CommsManager{
function getHeaderText(){
return 'this is BloggsCommsManager header';
}
function make($flag_int){
switch ($flag_int){
case self::APPT:
return new BloggsApptEncoder();
case self::CONTACT:
return new BloggsContachEncoder();
case self::TTD:
return new BloggsTtdEncoder();
}
}
function getFooterText(){
return 'this is BloggsCommsManager footer';
}
}
class MegaCommsManager extends CommsManager{
function getHeaderText(){
return 'this is MegaCommsManager header';
}
function make($flag_int){
switch ($flag_int){
case self::APPT:
return new MegaApptEncoder();
case self::CONTACT:
return new MegaContachEncoder();
case self::TTD:
return new MegaTtdEncoder();
}
}
function getFooterText(){
return 'this is MegaCommsManager footer';
}
}