Code Review Stack Exchange is a question and answer site for peer programmer code reviews. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Products Class that are like

Table Chair etc

Pls review it and give your thoughts and let me know if there are any rooms for improvisation.

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();
share|improve this question
    
seems to be redundant in case if some factory should build a furniture set which is comprised of 1 table and 2 chairs – RomanPerekhrest Mar 12 at 20:56
    
imho, having a WoodenFactory where you have to call makeWooden... methods, is not entirely how you would like your factory. A makeTable and makeChair will make more sence. Then every furnitureFactory can have a makeTable and makeChair, changing the factory from Wooden to Plastic just produces different objects. (instead of also changing the method calls) – Ronald Swets Mar 15 at 7:59

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.