0 votes
in Design Patterns by
Difference between strategy and state design pattern in Java?

1 Answer

0 votes
by
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.

Related questions

+1 vote
asked Oct 17, 2019 in Design Patterns by Robin
+1 vote
asked Oct 17, 2019 in Design Patterns by Robin
...