Skip to content

Commit

Permalink
documentation (commiting now from Guadeloupe)
Browse files Browse the repository at this point in the history
  • Loading branch information
Trismegiste committed Aug 17, 2013
1 parent 9a2536b commit 67bdb9f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
5 changes: 3 additions & 2 deletions Visitor/Role.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
8 changes: 7 additions & 1 deletion Visitor/RolePrintVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
10 changes: 8 additions & 2 deletions Visitor/RoleVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down

0 comments on commit 67bdb9f

Please sign in to comment.