Last active
January 3, 2016 19:09
-
-
Save amacgregor/8506593 to your computer and use it in GitHub Desktop.
Example for Design Patterns in PHP: Using Factories
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 Product | |
{ | |
private $sku; | |
private $name; | |
protected $type = null; | |
public function __construct($sku, $name) | |
{ | |
$this->sku = $sku; | |
$this->name = $name; | |
} | |
public function getSku() | |
{ | |
return $this->sku; | |
} | |
public function getName() | |
{ | |
return $this->name; | |
} | |
public function getType() | |
{ | |
return $this->type; | |
} | |
} | |
class Product_Chair extends Product | |
{ | |
protected $type = 'chair'; | |
} | |
class Product_Table extends Product | |
{ | |
protected $type = 'table'; | |
} | |
class Product_Bookcase extends Product | |
{ | |
protected $type = 'bookcase'; | |
} | |
class Product_Sofa extends Product | |
{ | |
protected $type = 'sofa'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment