CSC/ECE 517 Fall 2012/ch1b 2w41 dc: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
(Created page with "2w41. State pattern and the related patterns (Bridge, Strategy) State and Bridge patterns use the same structure to solve different problems: State allows an object’s beha...")
 
No edit summary
Line 1: Line 1:
2w41. State pattern and the related patterns (Bridge, Strategy)
= State pattern and the related patterns =


    State and Bridge patterns use the same structure to solve different problems: State allows an object’s behavior to change along with its state, while Bridge’s intent is to decouple an abstraction from its implementation so that the two can vary independently.
The [http://en.wikipedia.org/wiki/State_pattern State pattern] allows an object to completely change its behavior and the change depends on its current internal state. Alternatively, a [http://www.ipipan.gda.pl/~marek/objects/TOA/oobasics/oobasics.html#objects monolithic object's] behavior is a function of its state, and it must change its behavior at run-time depending on that state. State pattern is closely related to [http://en.wikipedia.org/wiki/Strategy_pattern Strategy pattern] and [http://en.wikipedia.org/wiki/Bridge_pattern Bridge pattern]. We shall discuss the three patterns, their structures, advantages & disadvantages.


    Strategy has 2 different implementations, the first is similar to State. The difference is in binding times (Strategy is a bind-once pattern, whereas State is more dynamic).
__TOC__


= Description =


Based on these lines, explain how the State pattern is related to or differ from the above patterns. Give suitable examples to explain the relationship or difference between the patterns.
The state pattern is behavioral as it defines how communication between classes or entities is controlled. It is used in programming to define the state of an object.

Revision as of 20:22, 19 November 2012

State pattern and the related patterns

The State pattern allows an object to completely change its behavior and the change depends on its current internal state. Alternatively, a monolithic object's behavior is a function of its state, and it must change its behavior at run-time depending on that state. State pattern is closely related to Strategy pattern and Bridge pattern. We shall discuss the three patterns, their structures, advantages & disadvantages.

Description

The state pattern is behavioral as it defines how communication between classes or entities is controlled. It is used in programming to define the state of an object.