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: "Prabodh Saha" <prabodhs AT ivycomptech.com>
  • To: "Bharathi Thiyagarajan" <bharathi.thiyagarajan AT adcc.alcatel.be>, "gag-of-4-patterns" <gang-of-4-patterns AT cs.uiuc.edu>
  • Subject: RE: [gang-of-4-patterns] state and strategy
  • Date: Fri, 19 Dec 2003 11:23:01 +0530
  • Importance: Normal
  • List-archive: <http://mail.cs.uiuc.edu/pipermail/gang-of-4-patterns/>
  • List-id: Design Patterns discussion <gang-of-4-patterns.cs.uiuc.edu>

Strategy:
is used for choosing a specific algroithms from a pool of different ones.
Here the algorithm is chosen by the "client application" that uses the
Strategy object.
Typically a strategy object provides a public changeAlgorithm() method,
meant to be
used by the client code at its wish. Where the instance of the "desired
algorithm" object
is provided by the client code and passed to the strategy using
strategy.changeAlgorithm(desiredAlgorithm).
After doing this the client application calls other methods on the strategy
to get results
using the desired algorithm.

HENCE THE STATE OF THE STRATEGY - ie. its holding of Algorithm - IS
MANIPULATED EXTERNALLY.

State:
Is a pattern where an object is meant to maintain / manipulate its state
"internally".
The object (say called: OBJ) typically holds a reference to its state
object.
The instance of the sate object referred, does define the behaviour of the
OBJ.
(i.e. the response of all the public methods OBJ has will depend on its
state-object)

This object(OBJ), which is maintaining its state, does not allow it's user
(ie. the client
application) to change its state "externally" to some instance created by
the user.

UNLIKE STRATEGY PATTERN:
~~~~~~~~~~~~~~~~~~~~~~~
The client code can NOT set the state of OBJ to any instance of
sate-object created by it.
In fact The client code has NO IDEA of the different state-objects
typically held by OBJ.


Regards,
Prabodh

-----Original Message-----
From:
gang-of-4-patterns-admin AT cs.uiuc.edu
[mailto:gang-of-4-patterns-admin AT cs.uiuc.edu]On
Behalf Of Bharathi
Thiyagarajan
Sent: Thursday, December 18, 2003 6:04 PM
To: gag-of-4-patterns
Subject: [gang-of-4-patterns] state and strategy


Hello *

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

Thanks & regards
bharathi





_______________________________________________
gang-of-4-patterns mailing list
gang-of-4-patterns AT cs.uiuc.edu
http://mail.cs.uiuc.edu/mailman/listinfo/gang-of-4-patterns





Archive powered by MHonArc 2.6.16.

Top of Page