Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Module 4] Visitor design pattern - List Filtering #39

Open
xgillard opened this issue Dec 2, 2020 · 0 comments
Open

[Module 4] Visitor design pattern - List Filtering #39

xgillard opened this issue Dec 2, 2020 · 0 comments

Comments

@xgillard
Copy link
Collaborator

xgillard commented Dec 2, 2020

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 acceptmethod, 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant