#!/bin/env/php <?php abstract class ApptEncoder { abstract function encode(); }
class XmlApptEncoder extends ApptEncoder { function encode() { return "Appointment data encoded in XmlApptEnder format\n"; } }
class JsonApptEncoder extends ApptEncoder { function encode() { return "Appointment data encoded in JsonApptEnder format\n"; } }
abstract class CommsManager { abstract function getHeaderText(); abstract function getApptEncoder(); abstract function getTtdEncoder(); abstract function getContactEncoder(); abstract function getFooterText(); }
class XmlCommsManager extends CommsManager { function getHeaderText() { return "Xml header\n"; }
function getApptEncoder() { return new XmlApptEncoder(); }
function getTtdEncoder() { return new XmlTtdEncoder(); }
function getContactEncoder() { return new XmlContactEncoder(); }
function getFooterText() { return "Xml footer\n"; } }
class JsonCommsManager extends CommsManager { function getHeaderText() { return "Json header\n"; }
function getApptEncoder() { return new JsonApptEncoder(); }
function getTtdEncoder() { return new JsonTtdEncoder(); }
function getContactEncoder() { return new JsonContactEncoder(); }
function getFooterText() { return "Json footer\n"; } }
$obj = new XmlCommsManager(); print $obj->getHeaderText(); print $obj->getApptEncoder()->encode(); print $obj->getFooterText();
function getPlains( ) { return clone $this->plains; }
function getForest( ) { return clone $this->forest; } }
$factory = new TerrainFactory( new EarthSea(), new EarthPlains(), new EarthForest() ); print_r( $factory->getSea() ); print_r( $factory->getPlains() ); print_r( $factory->getForest() );