Merge branch 'pr/107' into master

This commit is contained in:
Dominik Liebler
2014-08-24 15:54:50 +02:00
137 changed files with 14622 additions and 4 deletions

View File

@@ -4,3 +4,7 @@
To create series of related or dependent objects without specifying their concrete classes.
Usually the created classes all implement the same interface. The client of the abstract factory does not care about how these objects are created, he just knows how they go together.
## UML Diagram
![Alt AbstractFactory UML Diagram](uml/uml.png)

View File

@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<Diagram>
<ID>PHP</ID>
<OriginalElement>\DesignPatterns\Creational\AbstractFactory\AbstractFactory</OriginalElement>
<nodes>
<node x="281.0" y="228.0">\DesignPatterns\Creational\AbstractFactory\Html\Text</node>
<node x="150.0" y="229.0">\DesignPatterns\Creational\AbstractFactory\Html\Picture</node>
<node x="223.0" y="117.0">\DesignPatterns\Creational\AbstractFactory\HtmlFactory</node>
<node x="0.0" y="117.0">\DesignPatterns\Creational\AbstractFactory\JsonFactory</node>
<node x="126.0" y="0.0">\DesignPatterns\Creational\AbstractFactory\AbstractFactory</node>
<node x="0.0" y="229.0">\DesignPatterns\Creational\AbstractFactory\MediaInterface</node>
</nodes>
<notes />
<edges>
<edge source="\DesignPatterns\Creational\AbstractFactory\HtmlFactory" target="\DesignPatterns\Creational\AbstractFactory\AbstractFactory">
<point x="0.0" y="-33.5" />
<point x="324.5" y="92.0" />
<point x="256.5" y="92.0" />
<point x="43.5" y="33.5" />
</edge>
<edge source="\DesignPatterns\Creational\AbstractFactory\JsonFactory" target="\DesignPatterns\Creational\AbstractFactory\AbstractFactory">
<point x="0.0" y="-33.5" />
<point x="101.5" y="92.0" />
<point x="169.5" y="92.0" />
<point x="-43.5" y="33.5" />
</edge>
</edges>
<settings layout="Hierarchic Group" zoom="1.0" x="213.0" y="138.0" />
<SelectedNodes />
<Categories>
<Category>Fields</Category>
<Category>Constants</Category>
<Category>Constructors</Category>
<Category>Methods</Category>
</Categories>
<VISIBILITY>private</VISIBILITY>
</Diagram>

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 50 KiB

View File

@@ -13,3 +13,7 @@ Note: Builders have often a fluent interface, see the mock builder of PHPUnit fo
## Examples
* PHPUnit: Mock Builder
## UML Diagram
![Alt Builder UML Diagram](uml/uml.png)

View File

@@ -0,0 +1,54 @@
<?xml version="1.0" encoding="UTF-8"?>
<Diagram>
<ID>PHP</ID>
<OriginalElement>\DesignPatterns\Creational\Builder\BikeBuilder</OriginalElement>
<nodes>
<node x="211.45854922279796" y="202.76683937823833">\DesignPatterns\Creational\Builder\Parts\Door</node>
<node x="210.05958549222794" y="108.9585492227979">\DesignPatterns\Creational\Builder\Parts\Engine</node>
<node x="-194.71502590673578" y="194.2979274611399">\DesignPatterns\Creational\Builder\CarBuilder</node>
<node x="210.12694300518137" y="155.98963730569943">\DesignPatterns\Creational\Builder\Parts\Wheel</node>
<node x="111.45854922279796" y="157.76683937823833">\DesignPatterns\Creational\Builder\Parts\Bike</node>
<node x="42.458549222797956" y="157.76683937823833">\DesignPatterns\Creational\Builder\Parts\Car</node>
<node x="-405.7150259067358" y="194.2979274611399">\DesignPatterns\Creational\Builder\BikeBuilder</node>
<node x="-309.7150259067358" y="17.2979274611399">\DesignPatterns\Creational\Builder\BuilderInterface</node>
<node x="44.958549222797956" y="39.76683937823833">\DesignPatterns\Creational\Builder\Parts\Vehicle</node>
<node x="207.45854922279796" y="39.76683937823833">\DesignPatterns\Creational\Builder\Director</node>
</nodes>
<notes />
<edges>
<edge source="\DesignPatterns\Creational\Builder\BikeBuilder" target="\DesignPatterns\Creational\Builder\BuilderInterface">
<point x="0.0" y="-74.0" />
<point x="-310.2150259067358" y="169.2979274611399" />
<point x="-257.7150259067358" y="169.2979274611399" />
<point x="-52.0" y="63.5" />
</edge>
<edge source="\DesignPatterns\Creational\Builder\CarBuilder" target="\DesignPatterns\Creational\Builder\BuilderInterface">
<point x="0.0" y="-74.0" />
<point x="-101.21502590673578" y="169.2979274611399" />
<point x="-153.71502590673578" y="169.2979274611399" />
<point x="52.0" y="63.5" />
</edge>
<edge source="\DesignPatterns\Creational\Builder\Parts\Car" target="\DesignPatterns\Creational\Builder\Parts\Vehicle">
<point x="0.0" y="-13.5" />
<point x="66.95854922279796" y="132.76683937823833" />
<point x="73.45854922279796" y="132.76683937823833" />
<point x="-28.5" y="34.0" />
</edge>
<edge source="\DesignPatterns\Creational\Builder\Parts\Bike" target="\DesignPatterns\Creational\Builder\Parts\Vehicle">
<point x="0.0" y="-13.5" />
<point x="136.95854922279796" y="132.76683937823833" />
<point x="130.45854922279796" y="132.76683937823833" />
<point x="28.5" y="34.0" />
</edge>
</edges>
<settings layout="Hierarchic Group" zoom="1.0" x="-40.0" y="180.0" />
<SelectedNodes />
<Categories>
<Category>Fields</Category>
<Category>Constants</Category>
<Category>Constructors</Category>
<Category>Methods</Category>
</Categories>
<VISIBILITY>private</VISIBILITY>
</Diagram>

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 97 KiB

View File

@@ -9,3 +9,7 @@ For simple case, this abstract class could be just an interface
This pattern is a "real" Design Pattern because it achieves the "Dependency Inversion Principle" a.k.a the "D" in S.O.L.I.D principles.
It means the FactoryMethod class depends on abstractions, not concrete classes. This is the real trick compared to SimpleFactory or StaticFactory.
## UML Diagram
![Alt FactoryMethod UML Diagram](uml/uml.png)

View File

@@ -0,0 +1,55 @@
<?xml version="1.0" encoding="UTF-8"?>
<Diagram>
<ID>PHP</ID>
<OriginalElement>\DesignPatterns\Creational\FactoryMethod\Bicycle</OriginalElement>
<nodes>
<node x="-201.86528497409324" y="25.932642487046632">\DesignPatterns\Creational\FactoryMethod\FactoryMethod</node>
<node x="254.01554404145077" y="140.10880829015545">\DesignPatterns\Creational\FactoryMethod\Bicycle</node>
<node x="-109.36528497409324" y="183.93264248704662">\DesignPatterns\Creational\FactoryMethod\GermanFactory</node>
<node x="251.51554404145077" y="33.10880829015545">\DesignPatterns\Creational\FactoryMethod\VehicleInterface</node>
<node x="-279.36528497409324" y="183.93264248704662">\DesignPatterns\Creational\FactoryMethod\ItalianFactory</node>
<node x="389.01554404145077" y="140.10880829015545">\DesignPatterns\Creational\FactoryMethod\Ferrari</node>
<node x="99.01554404145077" y="130.10880829015545">\DesignPatterns\Creational\FactoryMethod\Porsche</node>
</nodes>
<notes />
<edges>
<edge source="\DesignPatterns\Creational\FactoryMethod\ItalianFactory" target="\DesignPatterns\Creational\FactoryMethod\FactoryMethod">
<point x="0.0" y="-23.5" />
<point x="-204.36528497409324" y="158.93264248704662" />
<point x="-160.61528497409324" y="158.93264248704662" />
<point x="-41.25" y="54.0" />
</edge>
<edge source="\DesignPatterns\Creational\FactoryMethod\Porsche" target="\DesignPatterns\Creational\FactoryMethod\VehicleInterface">
<point x="0.0" y="-44.0" />
<point x="166.51554404145077" y="105.10880829015545" />
<point x="271.51554404145077" y="105.10880829015545" />
<point x="-40.0" y="23.5" />
</edge>
<edge source="\DesignPatterns\Creational\FactoryMethod\Bicycle" target="\DesignPatterns\Creational\FactoryMethod\VehicleInterface">
<point x="0.0" y="-34.0" />
<point x="0.0" y="23.5" />
</edge>
<edge source="\DesignPatterns\Creational\FactoryMethod\GermanFactory" target="\DesignPatterns\Creational\FactoryMethod\FactoryMethod">
<point x="0.0" y="-23.5" />
<point x="-34.36528497409324" y="158.93264248704662" />
<point x="-78.11528497409324" y="158.93264248704662" />
<point x="41.25" y="54.0" />
</edge>
<edge source="\DesignPatterns\Creational\FactoryMethod\Ferrari" target="\DesignPatterns\Creational\FactoryMethod\VehicleInterface">
<point x="0.0" y="-34.0" />
<point x="446.51554404145077" y="105.10880829015545" />
<point x="351.51554404145077" y="105.10880829015545" />
<point x="40.0" y="23.5" />
</edge>
</edges>
<settings layout="Hierarchic Group" zoom="1.0" x="112.5" y="128.0" />
<SelectedNodes />
<Categories>
<Category>Fields</Category>
<Category>Constants</Category>
<Category>Constructors</Category>
<Category>Methods</Category>
</Categories>
<VISIBILITY>private</VISIBILITY>
</Diagram>

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 74 KiB

View File

@@ -10,3 +10,7 @@ To have only a list of named instances that are used, like a singleton but with
* 2 DB Connectors, e.g. one for MySQL, the other for SQLite
* multiple Loggers (one for debug messages, one for errors)
## UML Diagram
![Alt Multiton UML Diagram](uml/uml.png)

View File

@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<Diagram>
<ID>PHP</ID>
<OriginalElement>\DesignPatterns\Creational\Multiton\Multiton</OriginalElement>
<nodes>
<node x="0.0" y="0.0">\DesignPatterns\Creational\Multiton\Multiton</node>
</nodes>
<notes />
<edges />
<settings layout="Hierarchic Group" zoom="1.0" x="118.5" y="85.0" />
<SelectedNodes />
<Categories>
<Category>Fields</Category>
<Category>Constants</Category>
<Category>Constructors</Category>
<Category>Methods</Category>
</Categories>
<VISIBILITY>private</VISIBILITY>
</Diagram>

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.9 KiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 30 KiB

View File

@@ -6,3 +6,7 @@ The **object pool pattern** is a software creational design pattern that uses a
Object pooling can offer a significant performance boost in situations where the cost of initializing a class instance is high, the rate of instantiation of a class is high, and the number of instances in use at any one time is low. The pooled object is obtained in predictable time when creation of the new objects (especially over network) may take variable time.
However these benefits are mostly true for objects that are expensive with respect to time, such as database connections, socket connections, threads and large graphic objects like fonts or bitmaps. In certain situations, simple object pooling (that hold no external resources, but only occupy memory) may not be efficient and could decrease performance.
## UML Diagram
![Alt Pool UML Diagram](uml/uml.png)

View File

@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<Diagram>
<ID>PHP</ID>
<OriginalElement>\DesignPatterns\Creational\Pool\Processor</OriginalElement>
<nodes>
<node x="0.0" y="274.0">\DesignPatterns\Creational\Pool\Pool</node>
<node x="0.0" y="0.0">\DesignPatterns\Creational\Pool\Processor</node>
<node x="242.0" y="274.0">\DesignPatterns\Creational\Pool\Worker</node>
</nodes>
<notes />
<edges />
<settings layout="Hierarchic Group" zoom="0.9125295508274232" x="199.5" y="201.5" />
<SelectedNodes />
<Categories>
<Category>Fields</Category>
<Category>Constants</Category>
<Category>Constructors</Category>
<Category>Methods</Category>
</Categories>
<VISIBILITY>private</VISIBILITY>
</Diagram>

BIN
Creational/Pool/uml/uml.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

467
Creational/Pool/uml/uml.svg Normal file

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 60 KiB

View File

@@ -7,3 +7,7 @@ To avoid the cost of creating objects the standard way (new Foo()) and instead c
## Examples
* Large amounts of data (e.g. create 1,000,000 rows in a database at once via a ORM).
## UML Diagram
![Alt Prototype UML Diagram](uml/uml.png)

View File

@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<Diagram>
<ID>PHP</ID>
<OriginalElement>\DesignPatterns\Creational\Prototype\BarBookPrototype</OriginalElement>
<nodes>
<node x="60.0" y="0.0">\DesignPatterns\Creational\Prototype\BookPrototype</node>
<node x="155.0" y="178.0">\DesignPatterns\Creational\Prototype\FooBookPrototype</node>
<node x="0.0" y="178.0">\DesignPatterns\Creational\Prototype\BarBookPrototype</node>
</nodes>
<notes />
<edges>
<edge source="\DesignPatterns\Creational\Prototype\BarBookPrototype" target="\DesignPatterns\Creational\Prototype\BookPrototype">
<point x="0.0" y="-34.0" />
<point x="67.5" y="153.0" />
<point x="102.5" y="153.0" />
<point x="-42.5" y="64.0" />
</edge>
<edge source="\DesignPatterns\Creational\Prototype\FooBookPrototype" target="\DesignPatterns\Creational\Prototype\BookPrototype">
<point x="0.0" y="-34.0" />
<point x="222.5" y="153.0" />
<point x="187.5" y="153.0" />
<point x="42.5" y="64.0" />
</edge>
</edges>
<settings layout="Hierarchic Group" zoom="1.0" x="145.0" y="123.0" />
<SelectedNodes />
<Categories>
<Category>Fields</Category>
<Category>Constants</Category>
<Category>Constructors</Category>
<Category>Methods</Category>
</Categories>
<VISIBILITY>private</VISIBILITY>
</Diagram>

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.5 KiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 42 KiB

View File

@@ -7,3 +7,7 @@ ConcreteFactory is a simple factory pattern.
It differs from the static factory because it is NOT static and as you know: static => global => evil!
Therefore, you can have multiple factories, differently parametrized, you can subclass it and you can mock-up it.
## UML Diagram
![Alt SimpleFactory UML Diagram](uml/uml.png)

View File

@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<Diagram>
<ID>PHP</ID>
<OriginalElement>\DesignPatterns\Creational\SimpleFactory\ConcreteFactory</OriginalElement>
<nodes>
<node x="173.0" y="97.0">\DesignPatterns\Creational\SimpleFactory\Scooter</node>
<node x="0.0" y="189.0">\DesignPatterns\Creational\SimpleFactory\ConcreteFactory</node>
<node x="86.5" y="0.0">\DesignPatterns\Creational\SimpleFactory\VehicleInterface</node>
<node x="0.0" y="97.0">\DesignPatterns\Creational\SimpleFactory\Bicycle</node>
</nodes>
<notes />
<edges>
<edge source="\DesignPatterns\Creational\SimpleFactory\Bicycle" target="\DesignPatterns\Creational\SimpleFactory\VehicleInterface">
<point x="0.0" y="-23.5" />
<point x="76.5" y="72.0" />
<point x="124.75" y="72.0" />
<point x="-38.25" y="23.5" />
</edge>
<edge source="\DesignPatterns\Creational\SimpleFactory\Scooter" target="\DesignPatterns\Creational\SimpleFactory\VehicleInterface">
<point x="0.0" y="-23.5" />
<point x="249.5" y="72.0" />
<point x="201.25" y="72.0" />
<point x="38.25" y="23.5" />
</edge>
</edges>
<settings layout="Hierarchic Group" zoom="1.0" x="163.0" y="139.0" />
<SelectedNodes />
<Categories>
<Category>Fields</Category>
<Category>Constants</Category>
<Category>Constructors</Category>
<Category>Methods</Category>
</Categories>
<VISIBILITY>private</VISIBILITY>
</Diagram>

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 38 KiB

View File

@@ -12,6 +12,6 @@ To have only one instance of this object in the application that will handle all
* Logger (may also be a Multiton if there are many log files for several purposes)
* Lock file for the application (there is only one in the filesystem ...)
## Diagram
## UML Diagram
<img src="http://yuml.me/diagram/scruffy/class/[Singleton|-instance: Singleton|+getInstance(): Singleton;-__construct(): void;-__clone(): void;-__wakeup(): void]" >
![Alt Singleton UML Diagram](uml/uml.png)

View File

@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<Diagram>
<ID>PHP</ID>
<OriginalElement>\DesignPatterns\Creational\Singleton\Singleton</OriginalElement>
<nodes>
<node x="0.0" y="0.0">\DesignPatterns\Creational\Singleton\Singleton</node>
</nodes>
<notes />
<edges />
<settings layout="Hierarchic Group" zoom="1.0" x="96.0" y="64.5" />
<SelectedNodes />
<Categories>
<Category>Fields</Category>
<Category>Constants</Category>
<Category>Constructors</Category>
<Category>Methods</Category>
</Categories>
<VISIBILITY>private</VISIBILITY>
</Diagram>

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 25 KiB

View File

@@ -9,3 +9,7 @@ method to create all types of objects it can create. It is usually named `factor
## Examples
* Zend Framework: `Zend_Cache_Backend` or `_Frontend` use a factory method create cache backends or frontends
## UML Diagram
![Alt StaticFactory UML Diagram](uml/uml.png)

View File

@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<Diagram>
<ID>PHP</ID>
<OriginalElement>\DesignPatterns\Creational\StaticFactory\FormatNumber</OriginalElement>
<nodes>
<node x="114.0" y="77.0">\DesignPatterns\Creational\StaticFactory\FormatNumber</node>
<node x="-8.0" y="149.0">\DesignPatterns\Creational\StaticFactory\StaticFactory</node>
<node x="0.0" y="77.0">\DesignPatterns\Creational\StaticFactory\FormatString</node>
<node x="43.75" y="0.0">\DesignPatterns\Creational\StaticFactory\FormatterInterface</node>
</nodes>
<notes />
<edges>
<edge source="\DesignPatterns\Creational\StaticFactory\FormatString" target="\DesignPatterns\Creational\StaticFactory\FormatterInterface">
<point x="0.0" y="-13.5" />
<point x="47.0" y="52.0" />
<point x="75.0" y="52.0" />
<point x="-31.25" y="13.5" />
</edge>
<edge source="\DesignPatterns\Creational\StaticFactory\FormatNumber" target="\DesignPatterns\Creational\StaticFactory\FormatterInterface">
<point x="0.0" y="-13.5" />
<point x="165.5" y="52.0" />
<point x="137.5" y="52.0" />
<point x="31.25" y="13.5" />
</edge>
</edges>
<settings layout="Hierarchic Group" zoom="1.0" x="108.5" y="98.0" />
<SelectedNodes />
<Categories>
<Category>Fields</Category>
<Category>Constants</Category>
<Category>Constructors</Category>
<Category>Methods</Category>
</Categories>
<VISIBILITY>private</VISIBILITY>
</Diagram>

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.5 KiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 27 KiB