Files
DesignPatternsPHP/Creational/FactoryMethod/FactoryMethod.php
2015-12-21 07:28:20 -05:00

39 lines
744 B
PHP

<?php
namespace DesignPatterns\Creational\FactoryMethod;
/**
* class FactoryMethod.
*/
abstract class FactoryMethod
{
const CHEAP = 1;
const FAST = 2;
/**
* The children of the class must implement this method.
*
* Sometimes this method can be public to get "raw" object
*
* @param string $type a generic type
*
* @return VehicleInterface a new vehicle
*/
abstract protected function createVehicle($type);
/**
* Creates a new vehicle.
*
* @param int $type
*
* @return VehicleInterface a new vehicle
*/
public function create($type)
{
$obj = $this->createVehicle($type);
$obj->setColor('#f00');
return $obj;
}
}