From 67bdb9fede894be955bd39ab9c69e62434b09ea7 Mon Sep 17 00:00:00 2001 From: Trismegiste Date: Sat, 17 Aug 2013 19:41:18 -0400 Subject: [PATCH] documentation (commiting now from Guadeloupe) --- Visitor/Role.php | 5 +++-- Visitor/RolePrintVisitor.php | 8 +++++++- Visitor/RoleVisitor.php | 10 ++++++++-- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/Visitor/Role.php b/Visitor/Role.php index 83ee912..a2cec3f 100644 --- a/Visitor/Role.php +++ b/Visitor/Role.php @@ -9,13 +9,14 @@ namespace DesignPatterns\Visitor; * 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 544547a..24a8b1e 100644 --- a/Visitor/RolePrintVisitor.php +++ b/Visitor/RolePrintVisitor.php @@ -5,16 +5,22 @@ namespace DesignPatterns\Visitor; /** * 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 0f40667..634024d 100644 --- a/Visitor/RoleVisitor.php +++ b/Visitor/RoleVisitor.php @@ -5,13 +5,19 @@ namespace DesignPatterns\Visitor; /** * 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 */