Last active
December 29, 2015 16:09
-
-
Save craigtaub/7695094 to your computer and use it in GitHub Desktop.
Factory for categories
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
abstract class Channel | |
{ | |
protected $_identifier; | |
protected $_id; | |
protected $_iblId; | |
public function getIdentifier() { | |
return $this->_identifier; | |
} | |
public function getId() { | |
return $this->_id; | |
} | |
public function getIblid() { | |
return $this->_iblId; | |
} | |
//Additional channel logic | |
} | |
class Channels_BbcOne extends Channel | |
{ | |
//this is all the channel objects will ever have. | |
public function __construct(){ | |
$this->_identifier = 'bbcone'; | |
$this->_id = 'bbc_one'; | |
$this->_iblId = 'bbc_one_london'; | |
} | |
} | |
class ChannelsFactory | |
{ | |
private $_channel; | |
public function __construct($channel) { | |
$this->_channel = $channel; | |
} | |
public function build() { | |
switch ($this->_channel) { | |
case 'bbcone': | |
return new Channels_BbcOne(); | |
break; | |
case 'bbctwo': | |
return new Channels_BbcTwo(); | |
break; | |
} | |
} | |
} | |
// USAGE: | |
$channel = 'bbcone'; //getParam or whatever | |
$channelFactory = new ChannelsFactory($channel); | |
$channelObject = $channelFactory->build(); | |
echo $channelObject->getId(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment