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

State Pattern Standard Implementation added #5945

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

State Pattern Standard Implementation added #5945

wants to merge 4 commits into from

Conversation

ighosh98
Copy link

@ighosh98 ighosh98 commented Oct 3, 2020

Fixes issue:

#5924 is fixed in Java

Changes:

State Pattern implemented in Java. In this commit I have implemented two states: Start State and Stop State. This model can be extended to a multi-state solution

@ighosh98 ighosh98 mentioned this pull request Oct 3, 2020
4 tasks
Copy link
Member

@Devansh-Maurya Devansh-Maurya left a comment

Choose a reason for hiding this comment

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

The implementation does not live up to the definition of the state pattern. Your State interface has a function named goNext() but it is not changing the state of the context. The Client should not need to change the state of the Context by itself. If you are doing this, you are losing the power of the state pattern. You should delegate the responsibility to change states to the States themselves.

Also, the Context should not implement the State interface as it is not a State. It is the object that has State.

Please refer to this resource (or any other resource that you found helpful) for more information on the State pattern: https://sourcemaking.com/design_patterns/state

Copy link
Member

@Devansh-Maurya Devansh-Maurya left a comment

Choose a reason for hiding this comment

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

  1. Please keep classes in separate files.
  2. Group similar classes in the same package.
  3. Structure packages according to the UML diagram of the pattern.

@ighosh98
Copy link
Author

ighosh98 commented Oct 3, 2020

Thanks. I'll work on it.

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

Successfully merging this pull request may close these issues.

2 participants