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

From Expertiza_Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 3: Line 3:
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.
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.
__TOC__
__TOC__
= Description =
= 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. This pattern, also called as object for states pattern <ref>http://en.wikipedia.org/wiki/State_pattern</ref>, allows the class of an object to change at runtime without changing the interface used to access the object or losing the current state. This change in class is abstracted with the use of a wrapper object or context.<ref>http://www.blackwasp.co.uk/State.aspx</ref>
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. This pattern, also called as object for states pattern <ref>http://en.wikipedia.org/wiki/State_pattern</ref>, allows the class of an object to change at runtime without changing the interface used to access the object or losing the current state. This change in class is abstracted with the use of a wrapper object or context.<ref>http://www.blackwasp.co.uk/State.aspx</ref>
Creating object oriented state machines is one of the uses  of the state pattern. In this, the functionality of the object changes fundamentally according to its state. Using multiple concrete classes, each class inheriting from the same base class is an alternative to multiple number of 'if' or 'switch' statements.
Creating object oriented state machines is one of the uses  of the state pattern. In this, the functionality of the object changes fundamentally according to its state. Using multiple concrete classes, each class inheriting from the same base class is an alternative to multiple number of 'if' or 'switch' statements.



Revision as of 20:46, 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. This pattern, also called as object for states pattern <ref>http://en.wikipedia.org/wiki/State_pattern</ref>, allows the class of an object to change at runtime without changing the interface used to access the object or losing the current state. This change in class is abstracted with the use of a wrapper object or context.<ref>http://www.blackwasp.co.uk/State.aspx</ref>

Creating object oriented state machines is one of the uses of the state pattern. In this, the functionality of the object changes fundamentally according to its state. Using multiple concrete classes, each class inheriting from the same base class is an alternative to multiple number of 'if' or 'switch' statements.

References

<references/>