class BloggsApptEncoder extends ApptEncoder { function encode() { return "Данные о встрече закодированы в формате BloggsCal \n"; } } abstract class CommsManager { abstract function getHeaderText(); abstract function getApptEncoder(); abstract function getFooterText(); } class BloggsCommsManager extends CommsManager { function getHeaderText() { return "BloggsCal верхний колонтитул \n"; } function getApptEncoder() { return new BloggsApptEncoder(); } function getFooterText() { return "BloggsCal нижний колонтитул\n"; } } $s = new BloggsCommsManager(); //echo $s->getApptEncoder() echo $s->getApptEncoder()->encode();
{ function encode() { return "Данные закодированы в формате BloggsCal \n"; } } abstract class CommsManager { abstract function getHeaderText(); abstract function getApptEncoder(); abstract function getFooterText(); } class BloggsCommsManager extends CommsManager { function getHeaderText() { return "BloggsCal верхний колонтитул\n"; } function getApptEncoder() { return new BloggsApptEncoder(); } function getFooterText() { return "BloggsCal нижний колонтитул\n"; } } $Bloggs = new BloggsCommsManager(); print $Bloggs->getHeaderText(); print $Bloggs->getApptEncoder()->encode(); print $Bloggs->getFooterText();
abstract function getApptEncoder(); abstract function getTtdEncoder(); abstract function getContactEncoder(); abstract function getFooterText(); } class BloggsCommsManager extends CommsManager { function getHeaderText() { return "BloggsCal header\n"; } function getApptEncoder() { return new BloggsApptEncoder(); } function getTtdEncoder() { return new BloggsTtdEncoder(); } function getContactEncoder() { return new BloggsContactEncoder(); } function getFooterText() { return "BloggsCal footer\n"; } } $comms = new BloggsCommsManager(); $apptEncoder = $comms->getApptEncoder(); print $apptEncoder->encode();
} class BloggsCommsManager extends CommsManager { function getHeaderText() { return "Bloggs верхний колонтитул\n"; } function make($flag_int) { switch ($flag_int) { case self::APPT: return new BloggsApptEncoder(); break; case self::CONTACT: return new BloggsContactEncoder(); break; case self::TTD: return new BloggsTtdEncoder(); } } function getFooterText() { return "Bloggs нижний колонтитул\n"; } } $Bloggs = new BloggsCommsManager(); print $Bloggs->getHeaderText(); print $Bloggs->make($Bloggs::APPT)->encode(); print $Bloggs->make($Bloggs::CONTACT)->encode(); print $Bloggs->make($Bloggs::TTD)->encode(); print $Bloggs->getFooterText();
<?php if (!isset($_GET['useConfig'])) { /* case 1: default */ $bloggsCM = new BloggsCommsManager(); $megaCM = new MegaCommsManager(); $appt = $bloggsCM->make(CommsManager::APPT); $ttd = $megaCM->make(CommsManager::TTD); $cnt = $bloggsCM->make(CommsManager::CONTACT); echo $appt->encode(); //Appointment Encoded with BloggsCal format echo $ttd->encode(); //T0d0 Encoded with MegaCal format echo $cnt->encode(); //Contact Encoded with BloggsCal format } else { /* case 2: using AppConfig from the end of 9-th chapter */ $cm = AppConfig::getInstance()->getCommsManager(); $appt = $cm->make(CommsManager::APPT); $ttd = $cm->make(CommsManager::TTD); $cnt = $cm->make(CommsManager::CONTACT); echo $appt->encode(); //Appointment Encoded with MegaCal format echo $ttd->encode(); //T0d0 Encoded with MegaCal format echo $cnt->encode(); //Contact Encoded with MegaCal format