Skip to content

Instantly share code, notes, and snippets.

@amacgregor
Last active January 3, 2016 19:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amacgregor/8506593 to your computer and use it in GitHub Desktop.
Save amacgregor/8506593 to your computer and use it in GitHub Desktop.
Example for Design Patterns in PHP: Using Factories
<?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