A class that operates on different objects. Which one would be a better pattern to use?
-
Invoker pattern
-
Double Dispatch pattern
-
Factory pattern
-
Intercepting Filter
-
None of the above
B
Correct answer
Explanation
The Double Dispatch pattern (Visitor pattern family) allows an operation to vary based on both the object type and the operation type. It enables a class to perform different operations on different object types by dispatching twice - once on the object and once on the visitor. This is ideal when a class must operate on diverse object types with type-specific behavior. Invoker is Command pattern, Factory creates objects, Intercepting Filter modifies requests.