Created
August 27, 2014 02:13
-
-
Save wesleywillians/42726f5b802543c438c4 to your computer and use it in GitHub Desktop.
FactoryMethod
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 | |
| namespace Code; | |
| abstract class AbstractFactoryMethod | |
| { | |
| abstract function getLivroPHP($idoma); | |
| } |
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 | |
| namespace Code\Livros; | |
| abstract class AbstractLivro | |
| { | |
| abstract function getNome(); | |
| abstract function getAutor(); | |
| } |
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 | |
| namespace Code; | |
| class AlfaFactoryMethod extends AbstractFactoryMethod | |
| { | |
| public function getLivroPHP($idioma) | |
| { | |
| $livro = null; | |
| if($idioma == "pt_BR") { | |
| $livro = new Livros\LivroPHPAlfaPT(); | |
| } elseif($idioma == "en") { | |
| $livro = new Livros\LivroPHPAlfaEN(); | |
| } | |
| return $livro; | |
| } | |
| } |
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 | |
| namespace Code; | |
| class BetaFactoryMethod extends AbstractFactoryMethod | |
| { | |
| public function getLivroPHP($idioma) | |
| { | |
| $livro = null; | |
| if($idioma == "pt_BR") { | |
| $livro = new Livros\LivroPHPBetaPT(); | |
| } elseif($idioma == "en") { | |
| $livro = new Livros\LivroPHPBetaEN(); | |
| } | |
| return $livro; | |
| } | |
| } |
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 | |
| define('CLASS_DIR', 'src/'); | |
| set_include_path(get_include_path().PATH_SEPARATOR.CLASS_DIR); | |
| spl_autoload_register(); | |
| $alfa = new \Code\AlfaFactoryMethod(); | |
| $livroAlfaEn = $alfa->getLivroPHP("en"); | |
| $livroAlfaPt = $alfa->getLivroPHP("pt_BR"); | |
| var_dump($livroAlfaEn, $livroAlfaPt); | |
| $beta = new \Code\BetaFactoryMethod(); | |
| $livroBetaEn = $beta->getLivroPHP("en"); | |
| $livroBetaPt = $beta->getLivroPHP("pt_BR"); | |
| var_dump($livroBetaEn, $livroBetaPt); |
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 | |
| namespace Code\Livros; | |
| class LivroPHPAlfaEN extends AbstractLivro | |
| { | |
| public function getNome() | |
| { | |
| return "Book PHP Alfa: English"; | |
| } | |
| public function getAutor() | |
| { | |
| return "Wesley Willians"; | |
| } | |
| } |
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 | |
| namespace Code\Livros; | |
| class LivroPHPAlfaPT extends AbstractLivro | |
| { | |
| public function getNome() | |
| { | |
| return "Livro PHP Alfa: Português"; | |
| } | |
| public function getAutor() | |
| { | |
| return "Wesley Willians"; | |
| } | |
| } |
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 | |
| namespace Code\Livros; | |
| class LivroPHPBetaEN extends AbstractLivro | |
| { | |
| public function getNome() | |
| { | |
| return "Book PHP Beta: English"; | |
| } | |
| public function getAutor() | |
| { | |
| return "Wesley Willians"; | |
| } | |
| } |
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 | |
| namespace Code\Livros; | |
| class LivroPHPBetaPT extends AbstractLivro | |
| { | |
| public function getNome() | |
| { | |
| return "Livro PHP Beta: Português"; | |
| } | |
| public function getAutor() | |
| { | |
| return "Wesley Willians"; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment