lundi 29 août 2016

PHP Factory Design Pattern

I am new to learning Design Patterns

I just created the following example, can i consider it as an implementation of factory design patter?

<?php

class Dove
{

}

class Falcon
{

}

class BirdsFactory
{

    function getDove()
    {
        return new Dove();
    }

    function getFalcon()
    {
        return new Falcon();
    }
}

class MainClass
{

    private $birdsFactory;

    public function __construct()
    {
        $this->birdsFactory = new BirdsFactory();
    }

    public function test()
    {
        $this->birdsFactory->getDove();
        $this->birdsFactory->getFalcon();
    }

}

Aucun commentaire:

Enregistrer un commentaire