gang-of-4-patterns AT lists.siebelschool.illinois.edu
Subject: Design Patterns discussion
List archive
- From: Ralph Johnson <johnson AT cs.uiuc.edu>
- To: gang-of-4-patterns AT cs.uiuc.edu, jfreeman AT midwaygames.com, kenchoweb AT hotmail.com
- Cc:
- Subject: RE: [gang-of-4-patterns] Pattern question: state vs. strategy
- Date: Wed, 6 Jul 2005 17:49:47 -0500 (CDT)
- List-archive: <http://mail.cs.uiuc.edu/pipermail/gang-of-4-patterns>
- List-id: Design Patterns discussion <gang-of-4-patterns.cs.uiuc.edu>
The class diagrams are pretty similar, but the code usually
looks a lot different. The State objects usually have no
instance variables and lots of methods that are not particuarlly
related to each other. There is very low coupling (or low cohesion)
beteween the methods of the state objects. The strategy objects
often (but not always) have instance variables and often have a
lot of methods in them that are called by other methods. Usually
there are a few public methods that call a bunch of private methods.
The state classes cause the context object to switch state, while
the strategy classes never tell their context to switch to a different
strategy.
The purpose of the patterns is fairly different. You think of a
state pattern as a way to implement an object whose behavior is
state dependent. You think of a strategy pattern as a way to
encapsulate algorithms and switch from one to another. Of course,
if the only part of the object that is state dependent is one
method then there isn't much difference.
-Ralph
- [gang-of-4-patterns] Pattern question: state vs. strategy, Freeman-Hargis, James, 07/06/2005
- Re: [gang-of-4-patterns] Pattern question: state vs. strategy, Robert Allan Schwartz, 07/06/2005
- Re: [gang-of-4-patterns] Pattern question: state vs. strategy, Clint Shank, 07/06/2005
- RE: [gang-of-4-patterns] Pattern question: state vs. strategy, Jesús Alonso, 07/06/2005
- Re: [gang-of-4-patterns] Pattern question: state vs. strategy, Peter Horan, 07/07/2005
- <Possible follow-up(s)>
- RE: [gang-of-4-patterns] Pattern question: state vs. strategy, jdeena, 07/06/2005
- RE: [gang-of-4-patterns] Pattern question: state vs. strategy, Jesús Alonso, 07/06/2005
- RE: [gang-of-4-patterns] Pattern question: state vs. strategy, Ralph Johnson, 07/06/2005
- Re: [gang-of-4-patterns] Pattern question: state vs. strategy, Robert Allan Schwartz, 07/06/2005
Archive powered by MHonArc 2.6.16.