Skip to Content.
Sympa Menu

gang-of-4-patterns - Re: [gang-of-4-patterns] state and strategy

gang-of-4-patterns AT lists.cs.illinois.edu

Subject: Design Patterns discussion

List archive

Re: [gang-of-4-patterns] state and strategy


Chronological Thread 
  • From: Wayne Cannon <wcannon AT sonic.net>
  • To: Thiyagarajan_BHARATHI/IN/ALCATEL@ALCATEL
  • Cc: gag-of-4-patterns <gang-of-4-patterns AT cs.uiuc.edu>
  • Subject: Re: [gang-of-4-patterns] state and strategy
  • Date: Sat, 20 Dec 2003 18:00:49 -0800
  • List-archive: <http://mail.cs.uiuc.edu/pipermail/gang-of-4-patterns/>
  • List-id: Design Patterns discussion <gang-of-4-patterns.cs.uiuc.edu>

Among other differences, the strategy pattern is a higher level of abstraction than the state pattern. Patterns are not mutually exclusinve of one another, i.e., often one pattern can be used in the implementation of another. For example the strategy pattern can be implemented using the state pattern (among other possible implementations)

The state pattern defines one particular implementation (with a couple of alternatives when it comes to the details) for switching between behaviors that differ from one state to another. There are numerous other patterns that can be used to implement similar behavior changes in different ways, including the factory patterns, the bridge pattern, and the template pattern -- depending on the type of behavior, the switching requirements, etc.

The strategy pattern defines a way to have multiple, separately encapsulated algorithms that are interchangeable. The strategy pattern does not define how or when to switch between interchangeable algorithms. Its focus is on the encapsulation of those algorithms. Often, the particular strategy is selected once based on the run-time environment and never changed. However, if the desired algorithm changes based on some state of the application, the state pattern may be an ideal mechanism for switching between algorithms. On the other hand, the factory patterns, the bridge pattern, the template pattern, etc., may be more appropriate for implementing the strategy pattern, i.e., for switching between algorithms.

Regards,
Wayne

Thiyagarajan_BHARATHI/IN/ALCATEL@ALCATEL
wrote:

Please can any one explain the difference between state and strategy
pattern, I am confused.

Thanks & regards
bharathi







Archive powered by MHonArc 2.6.16.

Top of Page