Created
December 15, 2013 23:43
-
-
Save azcdev/7979944 to your computer and use it in GitHub Desktop.
Los productos de las Factory en PHP
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 | |
| abstract class Motor { | |
| const DIESEL = 0; | |
| const GASOLINA = 1; | |
| const BIODIESEL = 2; | |
| protected $encendido = false; | |
| protected $cilindros; | |
| public function enciende() { | |
| if(!$this->encendido) { | |
| $this->encendido = true; | |
| echo "Encendiendo motor ... run run run\n"; | |
| } else { | |
| throw new Exception("Eh!! Ya encendiste el motor!\n"); | |
| } | |
| } | |
| } | |
| abstract class Carro { | |
| protected $motor; | |
| protected $encendido = false; | |
| public function enciende() { | |
| if(!$this->encendido) { | |
| $this->encendido = true; | |
| try { | |
| $this->motor->enciende(); | |
| } catch(Exception $e) { | |
| die($e->getMessage()); | |
| } | |
| } else { | |
| throw new Exception("El carro ya esta encendido!!\n"); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment