68 lines
1.2 KiB
ReStructuredText
Raw Normal View History

`Visitor`__
===========
2015-04-02 00:03:33 +02:00
Purpose
-------
The Visitor Pattern lets you outsource operations on objects to other
objects. The main reason to do this is to keep a separation of concerns.
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
-----------
.. image:: uml/uml.png
:alt: Alt Visitor UML Diagram
:align: center
Code
----
You can also find this code on `GitHub`_
2015-04-02 00:03:33 +02:00
2015-04-08 23:19:24 +02:00
RoleVisitorInterface.php
2015-04-02 00:03:33 +02:00
2015-04-08 23:19:24 +02:00
.. literalinclude:: RoleVisitorInterface.php
2015-04-02 00:03:33 +02:00
:language: php
:linenos:
2016-09-22 11:29:48 +02:00
RoleVisitor.php
2015-04-02 00:03:33 +02:00
2016-09-22 11:29:48 +02:00
.. literalinclude:: RoleVisitor.php
2015-04-02 00:03:33 +02:00
:language: php
:linenos:
2015-04-08 23:19:24 +02:00
Role.php
2015-04-02 00:03:33 +02:00
2015-04-08 23:19:24 +02:00
.. literalinclude:: Role.php
2015-04-02 00:03:33 +02:00
:language: php
:linenos:
User.php
.. literalinclude:: User.php
:language: php
:linenos:
2015-04-08 23:19:24 +02:00
Group.php
2015-04-02 00:03:33 +02:00
2015-04-08 23:19:24 +02:00
.. literalinclude:: Group.php
2015-04-02 00:03:33 +02:00
:language: php
:linenos:
Test
----
Tests/VisitorTest.php
.. literalinclude:: Tests/VisitorTest.php
:language: php
:linenos:
.. _`GitHub`: https://github.com/domnikl/DesignPatternsPHP/tree/master/Behavioral/Visitor
.. __: http://en.wikipedia.org/wiki/Visitor_pattern