Categories

Oct 17, 2019 in Design Patterns

Q: Difference between strategy and state design pattern in Java?

1 Answer

Oct 18, 2019
Both Strategy, as well as state design pattern, are similar in practice but they have different implementation following are some of the major differences between these two:

a.Strategy design pattern defines a set of algorithms to carry out a specific behavior whereas State design pattern allows an object to alter its behavior when it’s internal state changes.

b.Strategy design pattern does not allow us to store a reference to the context object whereas state design pattern stores the reference to the context object which contains them.

c.In strategy design pattern the client is aware of the strategy which is chosen for implementation whereas in state design pattern the client does not decide which state to be chosen for implementation.

d.Strategy pattern deals with HOW an object performs a certain task whereas state design pattern deals with what an object is.

e.There is no successor/predecessor relationship present in strategy design pattern whereas in state design pattern states are related to one/another as successor & predecessor.
Click here to read more about Loan/Mortgage
Click here to read more about Insurance

Related questions

Madanswer
Oct 17, 2019 in Design Patterns
Jan 27 in JAVA
Oct 17, 2019 in Design Patterns
...