40 lines
747 B
PHP
Raw Normal View History

2013-05-10 21:09:55 +02:00
<?php
namespace DesignPatterns\Creational\FactoryMethod;
2013-05-10 21:09:55 +02:00
/**
2013-09-24 13:31:37 +02:00
* class FactoryMethod
2013-05-10 21:09:55 +02:00
*/
abstract class FactoryMethod
{
2013-05-10 21:29:43 +02:00
const CHEAP = 1;
const FAST = 2;
2013-05-10 21:09:55 +02:00
/**
* 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
*
2013-09-13 14:19:55 +02:00
* @return VehicleInterface a new vehicle
2013-05-10 21:09:55 +02:00
*/
abstract protected function createVehicle($type);
/**
* Creates a new vehicle
*
2013-05-10 21:29:43 +02:00
* @param int $type
2013-05-10 21:09:55 +02:00
*
2013-09-13 14:19:55 +02:00
* @return VehicleInterface a new vehicle
2013-05-10 21:09:55 +02:00
*/
public function create($type)
{
$obj = $this->createVehicle($type);
$obj->setColor("#f00");
return $obj;
}
2013-09-11 16:35:18 +02:00
}