Merge remote-tracking branch 'Ulbrec87/master'

This commit is contained in:
Dominik Liebler 2014-04-22 10:21:43 +02:00
commit 49465fe6cb
8 changed files with 130 additions and 0 deletions

11
Bridge/Assemble.php Normal file
View File

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

20
Bridge/Car.php Normal file
View File

@ -0,0 +1,20 @@
<?php
namespace DesignPatterns\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();
}
}

20
Bridge/Motorcycle.php Normal file
View File

@ -0,0 +1,20 @@
<?php
namespace DesignPatterns\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();
}
}

14
Bridge/Produce.php Normal file
View File

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

6
Bridge/README.md Normal file
View File

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

22
Bridge/Vehicle.php Normal file
View File

@ -0,0 +1,22 @@
<?php
namespace DesignPatterns\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() {
}
}

11
Bridge/Workshop.php Normal file
View File

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

View File

@ -0,0 +1,26 @@
<?php
namespace DesignPatterns\Tests\Bridge;
use DesignPatterns\Bridge\Assemble;
use DesignPatterns\Bridge\Car;
use DesignPatterns\Bridge\Motorcycle;
use DesignPatterns\Bridge\Produce;
use DesignPatterns\Bridge\Vehicle;
use DesignPatterns\Bridge\Workshop;
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();
}
}