mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-08-02 13:07:27 +02:00
cs SimpleFactory and Builder
This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
namespace DesignPatterns\Builder\Parts;
|
||||
|
||||
/**
|
||||
* Vehicle is a contract for a vehicle
|
||||
* VehicleInterface is a contract for a vehicle
|
||||
*/
|
||||
abstract class Vehicle
|
||||
{
|
||||
|
@@ -9,7 +9,7 @@ namespace DesignPatterns\SimpleFactory;
|
||||
/**
|
||||
* Bicycle is a bicycle
|
||||
*/
|
||||
class Bicycle implements Vehicle
|
||||
class Bicycle implements VehicleInterface
|
||||
{
|
||||
|
||||
public function driveTo($destination)
|
||||
|
@@ -36,7 +36,7 @@ class ConcreteFactory
|
||||
* Creates a vehicle
|
||||
*
|
||||
* @param string $type a known type key
|
||||
* @return Vehicle a new instance of Vehicle
|
||||
* @return VehicleInterface a new instance of VehicleInterface
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public function createVehicle($type)
|
||||
|
@@ -1,20 +1,17 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* DesignPatternPHP
|
||||
*/
|
||||
|
||||
namespace DesignPatterns\SimpleFactory;
|
||||
|
||||
/**
|
||||
* Scooter is a Scooter
|
||||
*/
|
||||
class Scooter implements Vehicle
|
||||
class Scooter implements VehicleInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @param mixed $destination
|
||||
*/
|
||||
public function driveTo($destination)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,16 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* DesignPatternPHP
|
||||
*/
|
||||
|
||||
namespace DesignPatterns\SimpleFactory;
|
||||
|
||||
/**
|
||||
* Vehicle is a contract for a vehicle
|
||||
*/
|
||||
interface Vehicle
|
||||
{
|
||||
|
||||
function driveTo($destination);
|
||||
}
|
16
SimpleFactory/VehicleInterface.php
Normal file
16
SimpleFactory/VehicleInterface.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace DesignPatterns\SimpleFactory;
|
||||
|
||||
/**
|
||||
* VehicleInterface is a contract for a vehicle
|
||||
*/
|
||||
interface VehicleInterface
|
||||
{
|
||||
/**
|
||||
* @param mixed $destination
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function driveTo($destination);
|
||||
}
|
@@ -35,7 +35,7 @@ class SimpleFactoryTest extends \PHPUnit_Framework_TestCase
|
||||
public function testCreation($type)
|
||||
{
|
||||
$obj = $this->factory->createVehicle($type);
|
||||
$this->assertInstanceOf('DesignPatterns\SimpleFactory\Vehicle', $obj);
|
||||
$this->assertInstanceOf('DesignPatterns\SimpleFactory\VehicleInterface', $obj);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -25,7 +25,7 @@ class StaticFactoryTest extends \PHPUnit_Framework_TestCase
|
||||
public function testCreation($type)
|
||||
{
|
||||
$obj = StaticFactory::factory($type);
|
||||
$this->assertInstanceOf('DesignPatterns\StaticFactory\Formatter', $obj);
|
||||
$this->assertInstanceOf('DesignPatterns\StaticFactory\FormatterInterface', $obj);
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user