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

Acyclic Visitor pattern #734 #753

Merged
merged 25 commits into from
Jun 28, 2018
Merged

Acyclic Visitor pattern #734 #753

merged 25 commits into from
Jun 28, 2018

Conversation

Argyro-Sioziou
Copy link
Contributor

@Argyro-Sioziou Argyro-Sioziou commented May 27, 2018

Acyclic Visitor pattern implementation

@Argyro-Sioziou
Copy link
Contributor Author

Is it #643 or should we do something?

@npathai npathai self-assigned this Jun 4, 2018
@npathai
Copy link
Contributor

npathai commented Jun 4, 2018

@Argyro-Sioziou Thanks for the PR 👍
I have picked up this task for review. Will revert with my changes if any in a day or two.

Copy link
Contributor

@npathai npathai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Argyro-Sioziou I am done with initial review. Really neat implementation 👍 . There are a few changes though. Let me know when you are done with the changes or have any questions.


private static final Logger LOGGER = LoggerFactory.getLogger(ConfigureForDosVisitor.class);

public Hayes() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to explicitly defining default constructor

}

/**
* Accept visitor
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: Accept all visitors, but honor only HayesVisitor.

* [Visitor Pattern](../visitor/README.md)

## Credits
* [Acyclic Visitor](http://condor.depaul.edu/dmumaugh/OOT/Design-Principles/acv.pdf)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: How about a consequences section explaining the good and bad points.

The good

  • No dependency cycles between class hierarchies
  • No need to recompile all the visitors if a new one is added
  • Does not cause compilation failure in existing visitors if class hierarchy has a new member

The bad

  • Violates the principle of least surprise or Liskov's Substitution principle by showing that it can accept all visitors but actually only being interested in particular visitors
  • Parallel hierarchy of visitors has to be created for all members in visitable class hierarchy

import org.slf4j.LoggerFactory;

/**
* CongigureForDosVisitor class implements both zoom's and hayes' visit method
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: CongigureForDosVisitor

Suggestion: we can have an interface called AllModemVisitor which extends all visitor interfaces. In our case we have two visitors but in real applications we can have many visitors. So it becomes cumbersome to extend all every time we need to visit all modems.

import org.slf4j.LoggerFactory;

/**
* CongigureForDosVisitor class implements both zoom's visit method for Unix
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: CongigureForDosVisitor

ConfigureForDosVisitor conDos = new ConfigureForDosVisitor();
Zoom zoom = mock(Zoom.class);

((ZoomVisitor)conDos).visit(zoom);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to cast explicitly here, as ConfigureForDosVisitor already implements ZoomVisitor

@Test
public void testVisitForHayes() {
ConfigureForDosVisitor conDos = new ConfigureForDosVisitor();
Hayes hayes = mock(Hayes.class);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same changes as above

Hayes hayes = mock(Hayes.class);

Assertions.assertThrows(ClassCastException.class, () -> {
((HayesVisitor)conUnix).visit(hayes);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test case doesn't test anything, the class cast exception occurs because ConfigureForUnixVisitor does not implement HayesVisitor and still we are explicitly casting it.

We can remove this test case

/**
* HayesVisitor test class
*/
public interface HayesVisitorTest {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tip: No need to create test classes for interfaces. Adds no value. So we should remove all test cases for interfaces

/**
* Modem test class
*/
public abstract class ModemTest {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove test case for interface.

@Argyro-Sioziou
Copy link
Contributor Author

@npathai Thank you a lot for the review. I have made the requested changes. I hope everything is fine now, otherwise let me know if there is anything else I shall change :)

@npathai
Copy link
Contributor

npathai commented Jun 26, 2018

@Argyro-Sioziou I apologize for the delay, was on a vacation. I will review it by tomorrow and let you know if any more changes are required else I will merge it.

@npathai npathai merged commit c7f9266 into iluwatar:master Jun 28, 2018
@iluwatar
Copy link
Owner

iluwatar commented Jul 7, 2018

Well done @Argyro-Sioziou 👍

@iluwatar
Copy link
Owner

@all-contributors please add @Argyro-Sioziou for code

@allcontributors
Copy link
Contributor

@iluwatar

I've put up a pull request to add @Argyro-Sioziou! 🎉

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

Successfully merging this pull request may close these issues.

4 participants