Created
November 16, 2015 14:19
-
-
Save kilip/7d82473b5a2e21c02af0 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 | |
class Computer | |
{ | |
protected $cpu; | |
protected $ram; | |
public function __construct($cpu,$ram) | |
{ | |
$this->cpu = $cpu; | |
$this->ram = $ram; | |
} | |
public function getSpecification() | |
{ | |
return "Computer CPU spec is: ".$cpu." with ".$ram." RAM"; | |
} | |
} | |
class ComputerFactory | |
{ | |
static public function create($cpu,$ram) | |
{ | |
return new Computer($cpu,$ram); | |
} | |
} | |
// have the factory to create computer | |
$myComputer = ComputerFactory::create("Core i7","16 GB"); | |
echo $myComputer;// will output: Computer CPU spec is: Core i7 with 16 GB RAM |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment