File tree Expand file tree Collapse file tree 3 files changed +18
-5
lines changed Expand file tree Collapse file tree 3 files changed +18
-5
lines changed Original file line number Diff line number Diff line change 9
9
* The Visitor Pattern lets you outsource operations on objects to other objects. The main reason to do this is to keep
10
10
* a seperation of concerns. But classes have to define an contract to allow visitors (the "accept" method in the example below).
11
11
*
12
- * The contract is an abstract class but you can have also a clean interface
12
+ * The contract is an abstract class but you can have also a clean interface.
13
+ * In that case, each Visitee has to choose itself which method to invoke on the visitor.
13
14
*/
14
15
abstract class Role
15
16
{
16
17
17
18
/**
18
- * This method handle a double dispatch based on the shortname of the Visitee
19
+ * This method handles a double dispatch based on the shortname of the Visitee
19
20
*
20
21
* Feel free to override it if your object must call another visiting behavior
21
22
*
Original file line number Diff line number Diff line change 5
5
/**
6
6
* Visitor Pattern
7
7
*
8
- * An implementation of a Visitor
8
+ * An implementation of a concrete Visitor
9
9
*/
10
10
class RolePrintVisitor implements RoleVisitor
11
11
{
12
12
13
+ /**
14
+ * @inheritdoc
15
+ */
13
16
public function visitGroup (Group $ role )
14
17
{
15
18
echo "Role: " . $ role ->getName ();
16
19
}
17
20
21
+ /**
22
+ * @inheritdoc
23
+ */
18
24
public function visitUser (User $ role )
19
25
{
20
26
echo "Role: " . $ role ->getName ();
Original file line number Diff line number Diff line change 5
5
/**
6
6
* Visitor Pattern
7
7
*
8
- * The contract for the visitor
8
+ * The contract for the visitor.
9
+ *
10
+ * Note 1 : in C++ or java, with method polymorphism based on type-hint, there are many
11
+ * methods visit() with different type for the 'role' parameter.
12
+ *
13
+ * Note 2 : the visitor must not choose itself which method to
14
+ * invoke, it is the Visitee that make this decision.
9
15
*/
10
16
interface RoleVisitor
11
17
{
12
18
13
19
/**
14
- * Visit a user object
20
+ * Visit a User object
15
21
*
16
22
* @param \DesignPatterns\Visitor\User $role
17
23
*/
You can’t perform that action at this time.
0 commit comments