mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-07-31 20:20:15 +02:00
merge from master
This commit is contained in:
12
Structural/Bridge/Assemble.php
Normal file
12
Structural/Bridge/Assemble.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace DesignPatterns\Structural\Bridge;
|
||||
|
||||
class Assemble implements Workshop
|
||||
{
|
||||
|
||||
public function work()
|
||||
{
|
||||
print 'Assembled';
|
||||
}
|
||||
}
|
21
Structural/Bridge/BridgeTest.php
Normal file
21
Structural/Bridge/BridgeTest.php
Normal 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
22
Structural/Bridge/Car.php
Normal 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();
|
||||
}
|
||||
}
|
22
Structural/Bridge/Motorcycle.php
Normal file
22
Structural/Bridge/Motorcycle.php
Normal 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();
|
||||
}
|
||||
}
|
15
Structural/Bridge/Produce.php
Normal file
15
Structural/Bridge/Produce.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace DesignPatterns\Structural\Bridge;
|
||||
|
||||
/**
|
||||
* Concrete Implementation
|
||||
*/
|
||||
class Produce implements Workshop
|
||||
{
|
||||
|
||||
public function work()
|
||||
{
|
||||
print 'Produced ';
|
||||
}
|
||||
}
|
7
Structural/Bridge/README.md
Normal file
7
Structural/Bridge/README.md
Normal 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)
|
||||
|
||||
|
||||
|
23
Structural/Bridge/Vehicle.php
Normal file
23
Structural/Bridge/Vehicle.php
Normal 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()
|
||||
{
|
||||
}
|
||||
}
|
12
Structural/Bridge/Workshop.php
Normal file
12
Structural/Bridge/Workshop.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace DesignPatterns\Structural\Bridge;
|
||||
|
||||
/**
|
||||
* Implementer
|
||||
*/
|
||||
interface Workshop
|
||||
{
|
||||
|
||||
public function work();
|
||||
}
|
Reference in New Issue
Block a user