Products Class that are like
Table, Chair, etc.
Please review it and give your thoughts and let me know if there are any rooms for improvement.
Products.php
<?php
abstract class Products
{
}
class Table extends products
{
public function __construct()
{
echo "New Table Created";
}
}
class Chair extends products
{
public function __construct()
{
echo "New Chair Created";
}
}
Factory Class That can produce Plastic Furniture, Wooden Furniture
Abstract Factory Class - FurnitureClass
<?php
include "products.php";
abstract class FurnitureFactory
{
abstract function building();
}
class WoodenFactory extends FurnitureFactory
{
const TABLE = 1;
const CHAIRS = 2;
public function building()
{
echo "Building Wooden Furniture";
}
public function makeWoodenTable()
{
echo "Wooden ";
return new Table();
}
public function makeWoodenChair()
{
echo "Wooden ";
return new Chair();
}
}
class PlasticFactory extends FurnitureFactory
{
public function building()
{
echo "Building Plastic Furniture";
}
}
$wfactory = new WoodenFactory();
$wtable = $wfactory->makeWoodenTable();
$wchair - $wfactory->makeWoodenChair();
WoodenFactorywhere you have to callmakeWooden...methods, is not entirely how you would like your factory. AmakeTableandmakeChairwill make more sence. Then everyfurnitureFactorycan have amakeTableandmakeChair, changing the factory from Wooden to Plastic just produces different objects. (instead of also changing the method calls) \$\endgroup\$