diff --git a/Visitor/Role.php b/Visitor/Role.php index 83ee9123f..a2cec3fee 100644 --- a/Visitor/Role.php +++ b/Visitor/Role.php @@ -9,13 +9,14 @@ * The Visitor Pattern lets you outsource operations on objects to other objects. The main reason to do this is to keep * a seperation of concerns. But classes have to define an contract to allow visitors (the "accept" method in the example below). * - * The contract is an abstract class but you can have also a clean interface + * The contract is an abstract class but you can have also a clean interface. + * In that case, each Visitee has to choose itself which method to invoke on the visitor. */ abstract class Role { /** - * This method handle a double dispatch based on the shortname of the Visitee + * This method handles a double dispatch based on the shortname of the Visitee * * Feel free to override it if your object must call another visiting behavior * diff --git a/Visitor/RolePrintVisitor.php b/Visitor/RolePrintVisitor.php index 544547a58..24a8b1e34 100644 --- a/Visitor/RolePrintVisitor.php +++ b/Visitor/RolePrintVisitor.php @@ -5,16 +5,22 @@ /** * Visitor Pattern * - * An implementation of a Visitor + * An implementation of a concrete Visitor */ class RolePrintVisitor implements RoleVisitor { + /** + * @inheritdoc + */ public function visitGroup(Group $role) { echo "Role: " . $role->getName(); } + /** + * @inheritdoc + */ public function visitUser(User $role) { echo "Role: " . $role->getName(); diff --git a/Visitor/RoleVisitor.php b/Visitor/RoleVisitor.php index 0f40667c9..634024d1c 100644 --- a/Visitor/RoleVisitor.php +++ b/Visitor/RoleVisitor.php @@ -5,13 +5,19 @@ /** * Visitor Pattern * - * The contract for the visitor + * The contract for the visitor. + * + * Note 1 : in C++ or java, with method polymorphism based on type-hint, there are many + * methods visit() with different type for the 'role' parameter. + * + * Note 2 : the visitor must not choose itself which method to + * invoke, it is the Visitee that make this decision. */ interface RoleVisitor { /** - * Visit a user object + * Visit a User object * * @param \DesignPatterns\Visitor\User $role */