Skip to content

Latest commit

 

History

History
 
 

Visitor

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

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

Alt Visitor UML Diagram

Code

You can also find these code on GitHub

RoleVisitorInterface.php

RoleVisitorInterface.php

RolePrintVisitor.php

RolePrintVisitor.php

Role.php

Role.php

User.php

User.php

Group.php

Group.php

Test

Tests/VisitorTest.php

Tests/VisitorTest.php