Ejemplo n.º 1
0
<?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
Ejemplo n.º 2
0
    {
        return "BloggsCal footer\n";
    }
}
class MegaCommsManager extends CommsManager
{
    function getHeaderText()
    {
        return "MegaCal header\n";
    }
    function getApptEncoder()
    {
        return new MegaApptEncoder();
    }
    function getTtdEncoder()
    {
        return new MegaTtdEncoder();
    }
    function getContactEncoder()
    {
        return new MegaContactEncoder();
    }
    function getFooterText()
    {
        return "MegaCal footer\n";
    }
}
$mgr = new MegaCommsManager();
print $mgr->getHeaderText();
print $mgr->getApptEncoder()->encode();
print $mgr->getFooterText();
Ejemplo n.º 3
0
class MegaApptEncoder extends ApptEncoder
{
    function encode()
    {
        return 'this is mega object';
    }
}
abstract class CommsManager
{
    abstract function getApptEncoder();
}
class BloggerCommsManager extends CommsManager
{
    function getApptEncoder()
    {
        return new BloggerApptEncoder();
    }
}
class MegaCommsManager extends CommsManager
{
    function getApptEncoder()
    {
        return new MegaApptEncoder();
    }
}
$blogger = new BloggerCommsManager();
$bloggerOb = $blogger->getApptEncoder();
echo $bloggerOb->encode() . "<br/>";
$mega = new MegaCommsManager();
$megaOb = $mega->getApptEncoder();
echo $megaOb->encode();