Skip to Content.
Sympa Menu

gang-of-4-patterns - Re: [gang-of-4-patterns] Pattern question: state vs. strategy

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

Subject: Design Patterns discussion

List archive

Re: [gang-of-4-patterns] Pattern question: state vs. strategy


Chronological Thread 
  • From: Peter Horan <peter AT deakin.edu.au>
  • To: gang-of-4-patterns AT cs.uiuc.edu
  • Subject: Re: [gang-of-4-patterns] Pattern question: state vs. strategy
  • Date: Thu, 07 Jul 2005 15:29:52 +1000
  • List-archive: <http://mail.cs.uiuc.edu/pipermail/gang-of-4-patterns>
  • List-id: Design Patterns discussion <gang-of-4-patterns.cs.uiuc.edu>

Freeman-Hargis, James wrote:
I’m wondering if you can give me some additional details as to how these are different? Their applicability, purpose and structure seem nearly identical: make the behavior of the context class change dynamically as the state/strategy changes. Both patterns even mentions how they can be tied into the flyweight pattern. The only difference I can readily see is that the state pattern mentions transitions while the strategy does not. Am I missing something?

Their purpose is different.

An object that possesses state can change its state, make a transition,
in response to events received. The state pattern allows the object
behaviour - its response to events - to be changed by changing a
supplier object. The source of the change of state is usually internal
to the algorithm. For example, in drawing a polygon, the response to
mouse events depends on previous mouse events.

In the case of strategy, the behaviour is set at some configuration time
and remains fixed. The source is usually external. For example, the
driver to open a file is selected once depending on the device the file
resides on - disk, floppy, network, etc.

The structure of the two patterns is the same and I am sure the
distinction may not be as clear as in the examples. For example, if one
strategy fails, another is tried. Is that a state or stragey pattern?
--
Peter Horan School of Information Technology
peter AT deakin.edu.au
Deakin University
+61-3-5227 1234 (Voice) Geelong, Victoria 3217, AUSTRALIA
+61-3-5227 2028 (FAX) http://www.cm.deakin.edu.au/~peter

-- The Eiffel guarantee: From specification to implementation
-- (http://www.cetus-links.org/oo_eiffel.html)






Archive powered by MHonArc 2.6.16.

Top of Page