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

@@ -10,3 +10,7 @@ To build a chain of objects to handle a call in sequential order. If one object
* a Spam filter
* Caching: first object is an instance of e.g. a Memcached Interface, if that "misses" it delegates the call to the database interface
* Yii Framework: CFilterChain is a chain of controller action filters. the executing point is passed from one filter to the next along the chain, and only if all filters say "yes", the action can be invoked at last.
## UML Diagram
![Alt ChainOfResponsibility UML Diagram](uml/uml.png)

View File

@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<Diagram>
<ID>PHP</ID>
<OriginalElement>\DesignPatterns\Behavioral\ChainOfResponsibilities\Handler</OriginalElement>
<nodes>
<node x="54.5" y="0.0">\DesignPatterns\Behavioral\ChainOfResponsibilities\Handler</node>
<node x="0.0" y="158.0">\DesignPatterns\Behavioral\ChainOfResponsibilities\Responsible\SlowStorage</node>
<node x="154.0" y="158.0">\DesignPatterns\Behavioral\ChainOfResponsibilities\Responsible\FastStorage</node>
<node x="304.0" y="45.0">\DesignPatterns\Behavioral\ChainOfResponsibilities\Request</node>
</nodes>
<notes />
<edges>
<edge source="\DesignPatterns\Behavioral\ChainOfResponsibilities\Responsible\SlowStorage" target="\DesignPatterns\Behavioral\ChainOfResponsibilities\Handler">
<point x="0.0" y="-44.5" />
<point x="67.0" y="133.0" />
<point x="99.25" y="133.0" />
<point x="-44.75" y="54.0" />
</edge>
<edge source="\DesignPatterns\Behavioral\ChainOfResponsibilities\Responsible\FastStorage" target="\DesignPatterns\Behavioral\ChainOfResponsibilities\Handler">
<point x="0.0" y="-44.5" />
<point x="221.0" y="133.0" />
<point x="188.75" y="133.0" />
<point x="44.75" y="54.0" />
</edge>
</edges>
<settings layout="Hierarchic Group" zoom="1.0" x="188.0" y="123.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: 10 KiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 48 KiB

View File

@@ -15,3 +15,7 @@ Command can also be aggregated to combine more complex commands with minimum cop
* A text editor : all events are Command which can be undone, stacked and saved.
* Symfony2: SF2 Commands that can be run from the CLI are built with just the Command pattern in mind
* big CLI tools use subcommands to distribute various tasks and pack them in "modules", each of these can be implemented with the Command pattern (e.g. vagrant)
## UML Diagram
![Alt Command UML Diagram](uml/uml.png)

View File

@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<Diagram>
<ID>PHP</ID>
<OriginalElement>\DesignPatterns\Behavioral\Command\HelloCommand</OriginalElement>
<nodes>
<node x="185.0" y="15.0">\DesignPatterns\Behavioral\Command\Invoker</node>
<node x="0.0" y="97.0">\DesignPatterns\Behavioral\Command\HelloCommand</node>
<node x="189.0" y="139.0">\DesignPatterns\Behavioral\Command\Receiver</node>
<node x="10.0" y="0.0">\DesignPatterns\Behavioral\Command\CommandInterface</node>
</nodes>
<notes />
<edges>
<edge source="\DesignPatterns\Behavioral\Command\HelloCommand" target="\DesignPatterns\Behavioral\Command\CommandInterface">
<point x="0.0" y="-44.5" />
<point x="0.0" y="23.5" />
</edge>
</edges>
<settings layout="Hierarchic Group" zoom="1.0" x="171.0" y="93.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: 44 KiB

View File

@@ -11,3 +11,7 @@ To make an object iterable and to make it appear like a collection of objects.
## Note
Standard PHP Library (SPL) defines an interface Iterator which is best suited for this! Often you would want to implement the Countable interface too, to allow `count($object)` on your iterable object
## UML Diagram
![Alt Iterator UML Diagram](uml/uml.png)

View File

@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<Diagram>
<ID>PHP</ID>
<OriginalElement>\DesignPatterns\Behavioral\Iterator\Book</OriginalElement>
<nodes>
<node x="30.0" y="239.0">\DesignPatterns\Behavioral\Iterator\BookListReverseIterator</node>
<node x="315.380829015544" y="226.96891191709844">\DesignPatterns\Behavioral\Iterator\BookList</node>
<node x="0.0" y="0.0">\DesignPatterns\Behavioral\Iterator\BookListIterator</node>
<node x="296.0" y="0.0">\DesignPatterns\Behavioral\Iterator\Book</node>
</nodes>
<notes />
<edges>
<edge source="\DesignPatterns\Behavioral\Iterator\BookListReverseIterator" target="\DesignPatterns\Behavioral\Iterator\BookListIterator">
<point x="0.0" y="-64.5" />
<point x="0.0" y="94.5" />
</edge>
</edges>
<settings layout="Hierarchic Group" zoom="1.0" x="250.0" y="184.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: 15 KiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 80 KiB

View File

@@ -9,3 +9,7 @@ like a controller (but not in the sense of the MVC).
All components (called Colleague) are only coupled to the MediatorInterface and
it is a good thing because in OOP, one good friend is better than many. This
is the key-feature of this pattern.
## UML Diagram
![Alt Mediator UML Diagram](uml/uml.png)

View File

@@ -0,0 +1,46 @@
<?xml version="1.0" encoding="UTF-8"?>
<Diagram>
<ID>PHP</ID>
<OriginalElement>\DesignPatterns\Behavioral\Mediator\Colleague</OriginalElement>
<nodes>
<node x="196.3419689119171" y="221.44559585492226">\DesignPatterns\Behavioral\Mediator\Subsystem\Database</node>
<node x="-347.65803108808296" y="7.461139896373059">\DesignPatterns\Behavioral\Mediator\MediatorInterface</node>
<node x="55.34196891191709" y="211.44559585492226">\DesignPatterns\Behavioral\Mediator\Subsystem\Client</node>
<node x="-353.65803108808296" y="144.46113989637306">\DesignPatterns\Behavioral\Mediator\Mediator</node>
<node x="-65.65803108808291" y="221.44559585492226">\DesignPatterns\Behavioral\Mediator\Subsystem\Server</node>
<node x="38.84196891191709" y="72.44559585492226">\DesignPatterns\Behavioral\Mediator\Colleague</node>
</nodes>
<notes />
<edges>
<edge source="\DesignPatterns\Behavioral\Mediator\Subsystem\Server" target="\DesignPatterns\Behavioral\Mediator\Colleague">
<point x="0.0" y="-23.5" />
<point x="-15.158031088082907" y="186.44559585492226" />
<point x="64.50863557858375" y="186.44559585492226" />
<point x="-51.333333333333336" y="44.5" />
</edge>
<edge source="\DesignPatterns\Behavioral\Mediator\Mediator" target="\DesignPatterns\Behavioral\Mediator\MediatorInterface">
<point x="0.0" y="-84.0" />
<point x="0.0" y="43.5" />
</edge>
<edge source="\DesignPatterns\Behavioral\Mediator\Subsystem\Client" target="\DesignPatterns\Behavioral\Mediator\Colleague">
<point x="0.0" y="-33.5" />
<point x="0.0" y="44.5" />
</edge>
<edge source="\DesignPatterns\Behavioral\Mediator\Subsystem\Database" target="\DesignPatterns\Behavioral\Mediator\Colleague">
<point x="0.0" y="-23.5" />
<point x="247.8419689119171" y="186.44559585492226" />
<point x="167.17530224525044" y="186.44559585492226" />
<point x="51.33333333333334" y="44.5" />
</edge>
</edges>
<settings layout="Hierarchic Group" zoom="1.0" x="-27.0" y="160.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: 20 KiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 77 KiB

View File

@@ -16,3 +16,7 @@ When using this pattern, care should be taken if the originator may change other
* The seed of a pseudorandom number generator
* The state in a finite state machine
## UML Diagram
![Alt Momento UML Diagram](uml/uml.png)

View File

@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<Diagram>
<ID>PHP</ID>
<OriginalElement>\DesignPatterns\Behavioral\Memento\Caretaker</OriginalElement>
<nodes>
<node x="182.0" y="153.0">\DesignPatterns\Behavioral\Memento\Caretaker</node>
<node x="0.0" y="0.0">\DesignPatterns\Behavioral\Memento\Originator</node>
<node x="0.0" y="153.0">\DesignPatterns\Behavioral\Memento\Memento</node>
</nodes>
<notes />
<edges />
<settings layout="Hierarchic Group" zoom="1.0" x="131.0" y="121.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.2 KiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 40 KiB

View File

@@ -18,3 +18,7 @@ a statement like `if (!is_null($obj)) { $obj->callSomething(); }` anymore.
* Symfony2: null output in Symfony/Console
* null handler in a Chain of Responsibilities pattern
* null command in a Command pattern
## UML Diagram
![Alt NullObject UML Diagram](uml/uml.png)

View File

@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<Diagram>
<ID>PHP</ID>
<OriginalElement>\DesignPatterns\Behavioral\NullObject\Service</OriginalElement>
<nodes>
<node x="111.0" y="97.0">\DesignPatterns\Behavioral\NullObject\NullLogger</node>
<node x="0.0" y="97.0">\DesignPatterns\Behavioral\NullObject\PrintLogger</node>
<node x="46.0" y="0.0">\DesignPatterns\Behavioral\NullObject\LoggerInterface</node>
<node x="0.0" y="189.0">\DesignPatterns\Behavioral\NullObject\Service</node>
</nodes>
<notes />
<edges>
<edge source="\DesignPatterns\Behavioral\NullObject\NullLogger" target="\DesignPatterns\Behavioral\NullObject\LoggerInterface">
<point x="0.0" y="-23.5" />
<point x="156.5" y="72.0" />
<point x="128.5" y="72.0" />
<point x="27.5" y="23.5" />
</edge>
<edge source="\DesignPatterns\Behavioral\NullObject\PrintLogger" target="\DesignPatterns\Behavioral\NullObject\LoggerInterface">
<point x="0.0" y="-23.5" />
<point x="45.5" y="72.0" />
<point x="73.5" y="72.0" />
<point x="-27.5" y="23.5" />
</edge>
</edges>
<settings layout="Hierarchic Group" zoom="1.0" x="101.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: 8.5 KiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 39 KiB

View File

@@ -11,4 +11,8 @@ To implement a publish/subscribe behaviour to an object, whenever a "Subject" ob
## Note
PHP already defines two interfaces that can help to implement this pattern: SplObserver and SplSubject.
PHP already defines two interfaces that can help to implement this pattern: SplObserver and SplSubject.
## UML Diagram
![Alt Observer UML Diagram](uml/uml.png)

View File

@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<Diagram>
<ID>PHP</ID>
<OriginalElement>\DesignPatterns\Behavioral\Observer\User</OriginalElement>
<nodes>
<node x="239.0" y="0.0">\DesignPatterns\Behavioral\Observer\UserObserver</node>
<node x="0.0" y="137.0">\DesignPatterns\Behavioral\Observer\User</node>
<node x="8.0" y="0.0">\SplSubject</node>
</nodes>
<notes />
<edges>
<edge source="\DesignPatterns\Behavioral\Observer\User" target="\SplSubject">
<point x="0.0" y="-74.0" />
<point x="0.0" y="43.5" />
</edge>
</edges>
<settings layout="Hierarchic Group" zoom="1.0" x="186.0" y="142.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: 9.7 KiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 42 KiB

View File

@@ -5,3 +5,6 @@
Builds a clear specification of business rules, where objects can be checked against. The composite specification class has
one method called `isSatisfiedBy` that returns either true or false depending on whether the given object satisfies the specification.
## UML Diagram
![Alt Specification UML Diagram](uml/uml.png)

View File

@@ -0,0 +1,55 @@
<?xml version="1.0" encoding="UTF-8"?>
<Diagram>
<ID>PHP</ID>
<OriginalElement>\DesignPatterns\Behavioral\Specification\AbstractSpecification</OriginalElement>
<nodes>
<node x="168.0" y="314.0">\DesignPatterns\Behavioral\Specification\PriceSpecification</node>
<node x="551.0" y="333.5">\DesignPatterns\Behavioral\Specification\Not</node>
<node x="259.25" y="0.0">\DesignPatterns\Behavioral\Specification\SpecificationInterface</node>
<node x="383.0" y="323.5">\DesignPatterns\Behavioral\Specification\Plus</node>
<node x="259.25" y="157.0">\DesignPatterns\Behavioral\Specification\AbstractSpecification</node>
<node x="0.0" y="323.5">\DesignPatterns\Behavioral\Specification\Either</node>
<node x="0.0" y="487.0">\DesignPatterns\Behavioral\Specification\Item</node>
</nodes>
<notes />
<edges>
<edge source="\DesignPatterns\Behavioral\Specification\Plus" target="\DesignPatterns\Behavioral\Specification\AbstractSpecification">
<point x="0.0" y="-54.5" />
<point x="457.0" y="294.0" />
<point x="386.75" y="294.0" />
<point x="25.5" y="53.5" />
</edge>
<edge source="\DesignPatterns\Behavioral\Specification\AbstractSpecification" target="\DesignPatterns\Behavioral\Specification\SpecificationInterface">
<point x="0.0" y="-53.5" />
<point x="0.0" y="53.5" />
</edge>
<edge source="\DesignPatterns\Behavioral\Specification\PriceSpecification" target="\DesignPatterns\Behavioral\Specification\AbstractSpecification">
<point x="0.0" y="-64.0" />
<point x="265.5" y="294.0" />
<point x="335.75" y="294.0" />
<point x="-25.5" y="53.5" />
</edge>
<edge source="\DesignPatterns\Behavioral\Specification\Not" target="\DesignPatterns\Behavioral\Specification\AbstractSpecification">
<point x="0.0" y="-44.5" />
<point x="618.0" y="284.0" />
<point x="437.75" y="284.0" />
<point x="76.5" y="53.5" />
</edge>
<edge source="\DesignPatterns\Behavioral\Specification\Either" target="\DesignPatterns\Behavioral\Specification\AbstractSpecification">
<point x="0.0" y="-54.5" />
<point x="74.0" y="284.0" />
<point x="284.75" y="284.0" />
<point x="-76.5" y="53.5" />
</edge>
</edges>
<settings layout="Hierarchic Group" zoom="0.6476510067114094" x="342.5" y="288.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: 25 KiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 97 KiB

View File

@@ -3,3 +3,7 @@
## Purpose
Encapsulate varying behavior for the same routine based on an object's state. This can be a cleaner way for an object to change its behavior at runtime without resorting to large monolithic conditional statements.
## UML Diagram
![Alt State UML Diagram](uml/uml.png)

View File

@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<Diagram>
<ID>PHP</ID>
<OriginalElement>\DesignPatterns\Behavioral\State\OrderInterface</OriginalElement>
<nodes>
<node x="0.0" y="271.0">\DesignPatterns\Behavioral\State\OrderFactory</node>
<node x="178.0" y="117.0">\DesignPatterns\Behavioral\State\CreateOrder</node>
<node x="202.0" y="271.0">\DesignPatterns\Behavioral\State\OrderController</node>
<node x="102.5" y="0.0">\DesignPatterns\Behavioral\State\OrderInterface</node>
<node x="0.0" y="117.0">\DesignPatterns\Behavioral\State\ShippingOrder</node>
</nodes>
<notes />
<edges>
<edge source="\DesignPatterns\Behavioral\State\ShippingOrder" target="\DesignPatterns\Behavioral\State\OrderInterface">
<point x="0.0" y="-54.5" />
<point x="79.0" y="92.0" />
<point x="135.25" y="92.0" />
<point x="-32.75" y="33.5" />
</edge>
<edge source="\DesignPatterns\Behavioral\State\CreateOrder" target="\DesignPatterns\Behavioral\State\OrderInterface">
<point x="0.0" y="-54.5" />
<point x="257.0" y="92.0" />
<point x="200.75" y="92.0" />
<point x="32.75" y="33.5" />
</edge>
</edges>
<settings layout="Hierarchic Group" zoom="1.0" x="171.5" y="169.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: 12 KiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 59 KiB

View File

@@ -14,3 +14,7 @@ To separate strategies and to enable fast switching between them. Also this patt
* sorting a list of objects, one strategy by date, the other by id
* simplify unit testing: e.g. switching between file and in-memory storage
## UML Diagram
![Alt Strategy UML Diagram](uml/uml.png)

View File

@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<Diagram>
<ID>PHP</ID>
<OriginalElement>\DesignPatterns\Behavioral\Strategy\ComparatorInterface</OriginalElement>
<nodes>
<node x="324.0" y="6.0">\DesignPatterns\Behavioral\Strategy\ObjectCollection</node>
<node x="144.0" y="97.0">\DesignPatterns\Behavioral\Strategy\DateComparator</node>
<node x="67.0" y="0.0">\DesignPatterns\Behavioral\Strategy\ComparatorInterface</node>
<node x="0.0" y="97.0">\DesignPatterns\Behavioral\Strategy\IdComparator</node>
</nodes>
<notes />
<edges>
<edge source="\DesignPatterns\Behavioral\Strategy\IdComparator" target="\DesignPatterns\Behavioral\Strategy\ComparatorInterface">
<point x="0.0" y="-23.5" />
<point x="62.0" y="72.0" />
<point x="100.5" y="72.0" />
<point x="-33.5" y="23.5" />
</edge>
<edge source="\DesignPatterns\Behavioral\Strategy\DateComparator" target="\DesignPatterns\Behavioral\Strategy\ComparatorInterface">
<point x="0.0" y="-23.5" />
<point x="206.0" y="72.0" />
<point x="167.5" y="72.0" />
<point x="33.5" y="23.5" />
</edge>
</edges>
<settings layout="Hierarchic Group" zoom="1.0" x="259.5" y="72.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: 11 KiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 42 KiB

View File

@@ -12,3 +12,7 @@ How? With abstraction of course.
In other words, this is a skeleton of algorithm, well-suited for framework libraries. The user has just to implement one method and the superclass do the job.
It is an easy way to decouple concrete classes and reduce copy-paste, that's why you'll find it everywhere.
## UML Diagram
![Alt TemplateMethod UML Diagram](uml/uml.png)

View File

@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<Diagram>
<ID>PHP</ID>
<OriginalElement>\DesignPatterns\Behavioral\TemplateMethod\BeachJourney</OriginalElement>
<nodes>
<node x="152.0" y="177.0">\DesignPatterns\Behavioral\TemplateMethod\CityJourney</node>
<node x="47.0" y="0.0">\DesignPatterns\Behavioral\TemplateMethod\Journey</node>
<node x="0.0" y="177.0">\DesignPatterns\Behavioral\TemplateMethod\BeachJourney</node>
</nodes>
<notes />
<edges>
<edge source="\DesignPatterns\Behavioral\TemplateMethod\CityJourney" target="\DesignPatterns\Behavioral\TemplateMethod\Journey">
<point x="0.0" y="-23.5" />
<point x="218.0" y="152.0" />
<point x="189.5" y="152.0" />
<point x="47.5" y="63.5" />
</edge>
<edge source="\DesignPatterns\Behavioral\TemplateMethod\BeachJourney" target="\DesignPatterns\Behavioral\TemplateMethod\Journey">
<point x="0.0" y="-23.5" />
<point x="66.0" y="152.0" />
<point x="94.5" y="152.0" />
<point x="-47.5" y="63.5" />
</edge>
</edges>
<settings layout="Hierarchic Group" zoom="1.0" x="142.0" y="112.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: 35 KiB

View File

@@ -6,3 +6,7 @@ The Visitor Pattern lets you outsource operations on objects to other objects. T
But classes have to define a contract to allow visitors (the `Role::accept` method in the example).
The contract is an abstract class but you can have also a clean interface. In that case, each Visitor has to choose itself which method to invoke on the visitor.
## UML Diagram
![Alt Visitor UML Diagram](uml/uml.png)

View File

@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<Diagram>
<ID>PHP</ID>
<OriginalElement>\DesignPatterns\Behavioral\Visitor\Group</OriginalElement>
<nodes>
<node x="-159.5" y="-99.0">\DesignPatterns\Behavioral\Visitor\Role</node>
<node x="87.15544041450778" y="20.129533678756502">\DesignPatterns\Behavioral\Visitor\RolePrintVisitor</node>
<node x="-87.0" y="-2.0">\DesignPatterns\Behavioral\Visitor\Group</node>
<node x="90.65544041450778" y="-96.8704663212435">\DesignPatterns\Behavioral\Visitor\RoleVisitorInterface</node>
<node x="-245.0" y="-2.0">\DesignPatterns\Behavioral\Visitor\User</node>
</nodes>
<notes />
<edges>
<edge source="\DesignPatterns\Behavioral\Visitor\RolePrintVisitor" target="\DesignPatterns\Behavioral\Visitor\RoleVisitorInterface">
<point x="0.0" y="-33.5" />
<point x="0.0" y="33.5" />
</edge>
<edge source="\DesignPatterns\Behavioral\Visitor\User" target="\DesignPatterns\Behavioral\Visitor\Role">
<point x="0.0" y="-44.5" />
<point x="-176.0" y="-27.0" />
<point x="-128.25" y="-27.0" />
<point x="-31.25" y="23.5" />
</edge>
<edge source="\DesignPatterns\Behavioral\Visitor\Group" target="\DesignPatterns\Behavioral\Visitor\Role">
<point x="0.0" y="-44.5" />
<point x="-18.0" y="-27.0" />
<point x="-65.75" y="-27.0" />
<point x="31.25" y="23.5" />
</edge>
</edges>
<settings layout="Hierarchic Group" zoom="1.0" x="-3.5" y="-5.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: 11 KiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 55 KiB