Answer the question
In order to leave comments, you need to log in
What is the Visitor design pattern?
class MyClass1
{
function accept(OperationGroup $operation) {$operation->visitMyClass1($this);}
function method1() {}
function method2() {}
}
abstract class OperationGroup {}
class OperationGroup1 extends OperationGroup
{
function visitMyClass1(MyClass1 $myClass1) {$myClass1->method1(); /*.............*/ }
function visitMyClass2(MyClass2 $myClass2) {$myClass2->method1(); /*.............*/ }
}
$myClass1 = new MyClass1();
$operationGroup1 = new OperationGroup1();
$myClass1->accept($operationGroup1);
Answer the question
In order to leave comments, you need to log in
Look in the book "PHP. Programming Objects, Patterns and Techniques", page 266.
I do not remember exactly, but this pattern should also be well considered in Martin Fowler's book.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question