Last active
December 22, 2015 21:27
-
-
Save oliveiramiguel/3094793 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| <?php | |
| interface Model_Interface | |
| { | |
| } | |
| class Model_Cliente implements Model_Interface | |
| { | |
| protected $nome; | |
| protected $sobreNome; | |
| public function setNome($pNome) | |
| { | |
| $this->nome = $pNome; | |
| return $this; | |
| } | |
| public function setSobreNome($pSobreNome) | |
| { | |
| $this->sobreNome = $pSobreNome; | |
| return $this; | |
| } | |
| } | |
| abstract class Storage_Abstract | |
| { | |
| protected $adapter; | |
| public function __construct(Storage_Interface $adapter) | |
| { | |
| $this->adapter = $adapter; | |
| } | |
| abstract function save($entity); | |
| } | |
| class Storage_Cliente extends Storage_Abstract | |
| { | |
| public function save($entity){ | |
| //.... | |
| } | |
| } | |
| /** | |
| * Interface padrão para todos os adapters implementarem | |
| * Todos os adapters terão que ter esses métodos | |
| */ | |
| interface Storage_Interface | |
| { | |
| public function save(array $pData); | |
| public function delete($pWhere); | |
| public function update(array $pData, $pWhere = null); | |
| } | |
| /** | |
| * Adapter para salvar dados em XML | |
| */ | |
| class XMLStorage implements Storage_Interface | |
| { | |
| public function delete($pWhere) | |
| { | |
| //Lógica | |
| //... | |
| } | |
| public function update(array $pData, $pWhere = null) | |
| { | |
| //Lógica | |
| //... | |
| } | |
| public function save(array $pData) { | |
| //Lógica | |
| //.. | |
| } | |
| } | |
| //Adapter para salvar em banco de dados | |
| class DBStorage implements Storage_Interface | |
| { | |
| public function delete($pWhere) | |
| { | |
| //Lógica | |
| //... | |
| } | |
| public function update(array $pData, $pWhere = null) | |
| { | |
| //Lógica | |
| //... | |
| } | |
| public function save(array $pData) | |
| { | |
| //Lógica | |
| //.. | |
| } | |
| } | |
| //TESTES | |
| $modelXML = new Model_Cliente(); | |
| $modelXML->setNome("XML"); | |
| $modelXML->setSobreNome("Storage"); | |
| $storageXml = new Storage_Cliente(new XMLStorage); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment