FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [View Raw Code]   [Original HTTPS Page]

DesignPatternsPHP/Behavioral/Visitor at flyweight · JavaDevl/DesignPatternsPHP · GitHub

Latest commit

 

History

History
 
 

README.rst

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

Code

You can also find these code on GitHub

RoleVisitorInterface.php

.. literalinclude:: RoleVisitorInterface.php
   :language: php
   :linenos:

RolePrintVisitor.php

.. literalinclude:: RolePrintVisitor.php
   :language: php
   :linenos:

Role.php

.. literalinclude:: Role.php
   :language: php
   :linenos:

User.php

.. literalinclude:: User.php
   :language: php
   :linenos:

Group.php

.. literalinclude:: Group.php
   :language: php
   :linenos:

Test

Tests/VisitorTest.php

.. literalinclude:: Tests/VisitorTest.php
   :language: php
   :linenos:


Back | FazBrowse Home | New Git URL