[Module 4] Visitor design pattern - List Filtering
Opened this issue · 0 comments
This issue relates to #38 but is not a complete duplicate of it
Despite being titled "Visitor..." and forcing the implementation of two methods accept
and visit
, the pattern which need to be implemented in this exercise is a fancy variation of the Composite pattern. Not the Visitor.
This, for instance, is illustrated by the fact that Visitor
interface comprises only two signatures for the visit
method. One is visit(Object)
, the other is visit(Visitable)
. In a true visitor pattern, one would expect the definition of a visit
method for each and every type that might be encountered by the visitor. Also, all those types should be implementing an accept
method, otherwise no double dispatch is possible. Here, it is easy to see that one cannot just modify Object
to force it to implement accept
. Also, that would not make much sense since in java "everything is an object". Thus, this would mean that the visitor is universal and all other types would no longer need to implement accept
; thereby defeating the double dispatch purpose of the pattern.