diff --git a/Structural/Bridge/Assemble.php b/Structural/Bridge/Assemble.php deleted file mode 100644 index 9b9d114..0000000 --- a/Structural/Bridge/Assemble.php +++ /dev/null @@ -1,11 +0,0 @@ -workShop1->work(); - $this->workShop2->work(); - } -} diff --git a/Structural/Bridge/FormatterInterface.php b/Structural/Bridge/FormatterInterface.php new file mode 100644 index 0000000..d59a344 --- /dev/null +++ b/Structural/Bridge/FormatterInterface.php @@ -0,0 +1,8 @@ +implementation->format('Hello World'); + } +} diff --git a/Structural/Bridge/HtmlFormatter.php b/Structural/Bridge/HtmlFormatter.php new file mode 100644 index 0000000..79e49b5 --- /dev/null +++ b/Structural/Bridge/HtmlFormatter.php @@ -0,0 +1,11 @@ +%s

', $text); + } +} diff --git a/Structural/Bridge/Motorcycle.php b/Structural/Bridge/Motorcycle.php deleted file mode 100644 index f008785..0000000 --- a/Structural/Bridge/Motorcycle.php +++ /dev/null @@ -1,21 +0,0 @@ -workShop1->work(); - $this->workShop2->work(); - } -} diff --git a/Structural/Bridge/PlainTextFormatter.php b/Structural/Bridge/PlainTextFormatter.php new file mode 100644 index 0000000..af46283 --- /dev/null +++ b/Structural/Bridge/PlainTextFormatter.php @@ -0,0 +1,11 @@ +implementation = $printer; + } + + /** + * @param FormatterInterface $printer + */ + public function setImplementation(FormatterInterface $printer) + { + $this->implementation = $printer; + } + + abstract public function get(); +} diff --git a/Structural/Bridge/Tests/BridgeTest.php b/Structural/Bridge/Tests/BridgeTest.php index 0a89a86..2f70e87 100644 --- a/Structural/Bridge/Tests/BridgeTest.php +++ b/Structural/Bridge/Tests/BridgeTest.php @@ -2,24 +2,19 @@ namespace DesignPatterns\Structural\Bridge\Tests; -use DesignPatterns\Structural\Bridge\Assemble; -use DesignPatterns\Structural\Bridge\Car; -use DesignPatterns\Structural\Bridge\Motorcycle; -use DesignPatterns\Structural\Bridge\Produce; +use DesignPatterns\Structural\Bridge\HelloWorldService; +use DesignPatterns\Structural\Bridge\HtmlFormatter; +use DesignPatterns\Structural\Bridge\PlainTextFormatter; class BridgeTest extends \PHPUnit_Framework_TestCase { - public function testCar() + public function testCanPrintUsingThePlainTextPrinter() { - $vehicle = new Car(new Produce(), new Assemble()); - $this->expectOutputString('Car Produced Assembled'); - $vehicle->manufacture(); - } + $service = new HelloWorldService(new PlainTextFormatter()); + $this->assertEquals('Hello World', $service->get()); - public function testMotorcycle() - { - $vehicle = new Motorcycle(new Produce(), new Assemble()); - $this->expectOutputString('Motorcycle Produced Assembled'); - $vehicle->manufacture(); + // now change the implemenation and use the HtmlFormatter instead + $service->setImplementation(new HtmlFormatter()); + $this->assertEquals('

Hello World

', $service->get()); } } diff --git a/Structural/Bridge/Vehicle.php b/Structural/Bridge/Vehicle.php deleted file mode 100644 index 80311e1..0000000 --- a/Structural/Bridge/Vehicle.php +++ /dev/null @@ -1,20 +0,0 @@ -workShop1 = $workShop1; - $this->workShop2 = $workShop2; - } - - abstract public function manufacture(); -} diff --git a/Structural/Bridge/Workshop.php b/Structural/Bridge/Workshop.php deleted file mode 100644 index 9cb26c5..0000000 --- a/Structural/Bridge/Workshop.php +++ /dev/null @@ -1,11 +0,0 @@ - - - PHP - \DesignPatterns\Structural\Bridge\Vehicle - - \DesignPatterns\Structural\Bridge\Workshop - \DesignPatterns\Structural\Bridge\Car - \DesignPatterns\Structural\Bridge\Produce - \DesignPatterns\Structural\Bridge\Motorcycle - \DesignPatterns\Structural\Bridge\Assemble - \DesignPatterns\Structural\Bridge\Vehicle - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Fields - Constants - Constructors - Methods - - private - - + + + PHP + \DesignPatterns\Structural\Bridge\HtmlFormatter + + \DesignPatterns\Structural\Bridge\PlainTextFormatter + \DesignPatterns\Structural\Bridge\FormatterInterface + \DesignPatterns\Structural\Bridge\Service + \DesignPatterns\Structural\Bridge\HelloWorldService + \DesignPatterns\Structural\Bridge\HtmlFormatter + + + + + + + + + + + + + + + + + + + + + + + + Fields + Constants + Methods + + private + + diff --git a/Structural/Bridge/uml/uml.png b/Structural/Bridge/uml/uml.png index df6ce3c..6de5b02 100644 Binary files a/Structural/Bridge/uml/uml.png and b/Structural/Bridge/uml/uml.png differ diff --git a/Structural/Bridge/uml/uml.svg b/Structural/Bridge/uml/uml.svg index 189a7dc..9483eab 100644 --- a/Structural/Bridge/uml/uml.svg +++ b/Structural/Bridge/uml/uml.svg @@ -1,451 +1,661 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - work() - - - - - - - - - - - - - Workshop - - - Workshop - - - - - - - - - - - - - - - - - - - __construct(workShop1, workShop2) - - - - - - - - - - - - - manufacture() - - - - - - - - - - - - - Car - - - Car - - - - - - - - - - - - - - - - - - - work() - - - - - - - - - - - - - Produce - - - Produce - - - - - - - - - - - - - - - - - - - __construct(workShop1, workShop2) - - - - - - - - - - - - - manufacture() - - - - - - - - - - - - - Motorcycle - - - Motorcycle - - - - - - - - - - - - - - - - - - - work() - - - - - - - - - - - - - Assemble - - - Assemble - - - - - - - - - - - - - - - - - - - workShop1 - - - - - - - - - - workShop2 - - - - - - - - - - - - - __construct(workShop1, workShop2) - - - - - - - - - - - - - manufacture() - - - - - - - - - - - - - Vehicle - - - Vehicle - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + format(text) + + + + + + + + + + + + + PlainTextFormatter + + + PlainTextFormatter + + + + + + + + + + + + + + + + + + + + + + format(text) + + + + + + + + + + + + + PlainTextFormatter + + + PlainTextFormatter + + + + + + + + + + + + + + + + + + + + + + format(text) + + + + + + + + + + + + + FormatterInterface + + + FormatterInterface + + + + + + + + + + + + + + + + + + + + + + format(text) + + + + + + + + + + + + + FormatterInterface + + + FormatterInterface + + + + + + + + + + + + + + + + + + + + + + + + + implementation + + + + + + + + + + + + + + + + setImplementation(printer) + + + + + + + + + + + + + get() + + + + + + + + + + + + + Service + + + Service + + + + + + + + + + + + + + + + + + + + + + implementation + + + + + + + + + + + + + + + + + + + setImplementation(printer) + + + + + + + + + + + + + + + + get() + + + + + + + + + + + + + Service + + + Service + + + + + + + + + + + + + + + + + + + + + + get() + + + + + + + + + + + + + HelloWorldService + + + HelloWorldService + + + + + + + + + + + + + + + + + + + + + + get() + + + + + + + + + + + + + HelloWorldService + + + HelloWorldService + + + + + + + + + + + + + + + + + + + + + + format(text) + + + + + + + + + + + + + HtmlFormatter + + + HtmlFormatter + + + + + + + + + + + + + + + + + + + + + + format(text) + + + + + + + + + + + + + HtmlFormatter + + + HtmlFormatter + + + + + + + + + + + + +