Presentation is loading. Please wait.

Presentation is loading. Please wait.

State-Space and Behavior

Similar presentations


Presentation on theme: "State-Space and Behavior"— Presentation transcript:

1 State-Space and Behavior
State-Space and Behavior of a Class State-Space of a Subclass Behavior of a Subclass Class Invariant as a Restriction on a State-Space Preconditions and Postconditions

2 Abstraction by Class A class should represent a uniform abstraction of the properties of the individual objects that belong to that class abstraction: not necessarily every property in the real world uniform: apply to all objects in the class Two properties of a class state-space allowed behavior

3 State-Space of a Class The ensemble of all the permitted states of any object of the class state: the ordered set of object attribute values at a given time Dimensions of a state-space the coordinates needed to specify the state of a given object basic attributes defined on the class attributes derived from others are not considered as dimensions

4 Behavior of a Class The set of transitions that an object of the class is permitted to make between states in the state-space transition: change of object state when one or more of the attributes change values usually hop along the dimensions Not all paths in the state-space are allowed in a class

5 Example: Chess Knight vs. Queen Both have the same state-space
chessboard The two classes are different in behavior different moving rules Special Knight (Fig in P. 261) has different state-space from the original knight class

6 State-Space of a Subclass
The state-space of a subclass must be entirely contained within the state-space of its superclass the state-space of a subclass is confined by the state-space of its superclass a subclass usually has narrower ranges of values for the dimensions defined in the superclass The state-space of a subclass may have more dimensions the state-space extends from superclass

7 Behavior of a Subclass The behaviors of subclass and superclass have the similar relationship as the state-spaces Behavior Confinement closed behavior Behavior Extension extended behavior due to the extended state-space

8 Class Invariant A class invariant is a condition that every object of that class must satisfy at all times when the object is in equilibrium not in the middle of changing states special rules for attribute values Invariant Checking Points when the object is initialized at instantiation before any operation is executed after any operation is executed A subclass must obey the invariant of its superclass

9 Preconditions and Postconditions
To govern individual operations Every operation has a precondition and a postcondition Precondition a condition that must be true when the operation begins to execute, otherwise, refuse to execute Postcondition a condition that must be true when the operation ends its execution, otherwise, recover and fix

10 Design by Contract Use preconditions and postconditions as a contract between an operation and the message senders Message senders guarantee that the precondition is true before execution The operations guarantee that the postcondition is true after execution Basic Object-Oriented Design Approach formed by class invariant, preconditions, and postconditions


Download ppt "State-Space and Behavior"

Similar presentations


Ads by Google