Skip to content

Instantly share code, notes, and snippets.

@kilip
Created November 16, 2015 14:19
Show Gist options
  • Save kilip/7d82473b5a2e21c02af0 to your computer and use it in GitHub Desktop.
Save kilip/7d82473b5a2e21c02af0 to your computer and use it in GitHub Desktop.
<?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