merge from master

This commit is contained in:
Antonio Spinelli
2014-05-02 12:33:44 -03:00
parent 9beb7d9a58
commit 14a9dfe7cf
16 changed files with 325 additions and 17 deletions

View File

@@ -0,0 +1,12 @@
<?php
namespace DesignPatterns\Structural\Bridge;
class Assemble implements Workshop
{
public function work()
{
print 'Assembled';
}
}

View File

@@ -0,0 +1,21 @@
<?php
namespace DesignPatterns\Structural\Bridge;
class BridgeTest extends \PHPUnit_Framework_TestCase
{
public function testCar()
{
$vehicle = new Car(new Produce(), new Assemble());
$this->expectOutputString('Car Produced Assembled');
$vehicle->manufacture();
}
public function testMotorcycle()
{
$vehicle = new Motorcycle(new Produce(), new Assemble());
$this->expectOutputString('Motorcycle Produced Assembled');
$vehicle->manufacture();
}
}

22
Structural/Bridge/Car.php Normal file
View File

@@ -0,0 +1,22 @@
<?php
namespace DesignPatterns\Structural\Bridge;
/**
* Refined Abstraction
*/
class Car extends Vehicle
{
public function __construct(Workshop $workShop1, Workshop $workShop2)
{
parent::__construct($workShop1, $workShop2);
}
public function manufacture()
{
print 'Car ';
$this->workShop1->work();
$this->workShop2->work();
}
}

View File

@@ -0,0 +1,22 @@
<?php
namespace DesignPatterns\Structural\Bridge;
/**
* Refined Abstraction
*/
class Motorcycle extends Vehicle
{
public function __construct(Workshop $workShop1, Workshop $workShop2)
{
parent::__construct($workShop1, $workShop2);
}
public function manufacture()
{
print 'Motorcycle ';
$this->workShop1->work();
$this->workShop2->work();
}
}

View File

@@ -0,0 +1,15 @@
<?php
namespace DesignPatterns\Structural\Bridge;
/**
* Concrete Implementation
*/
class Produce implements Workshop
{
public function work()
{
print 'Produced ';
}
}

View File

@@ -0,0 +1,7 @@
## Purpose
Decouple an abstraction from its implementation so that the two can vary
independently. (http://en.wikipedia.org/wiki/Bridge_pattern)

View File

@@ -0,0 +1,23 @@
<?php
namespace DesignPatterns\Structural\Bridge;
/**
* Abstraction
*/
abstract class Vehicle
{
protected $workShop1;
protected $workShop2;
protected function __construct(Workshop $workShop1, Workshop $workShop2)
{
$this->workShop1 = $workShop1;
$this->workShop2 = $workShop2;
}
public function manufacture()
{
}
}

View File

@@ -0,0 +1,12 @@
<?php
namespace DesignPatterns\Structural\Bridge;
/**
* Implementer
*/
interface Workshop
{
public function work();
}

View File

@@ -5,6 +5,7 @@ ease the design by identifying a simple way to realize relationships between
entities.
* [Adapter](Adapter) [:notebook:](http://en.wikipedia.org/wiki/Adapter_pattern)
* [Bridge](Bridge) [:notebook:](http://en.wikipedia.org/wiki/Bridge_pattern)
* [Composite](Composite) [:notebook:](http://en.wikipedia.org/wiki/Composite_pattern)
* [DataMapper](DataMapper) [:notebook:](http://en.wikipedia.org/wiki/Data_mapper_pattern)
* [Decorator](Decorator) [:notebook:](http://en.wikipedia.org/wiki/Decorator_pattern)