Statechart diagrams
Statechart diagrams shows how the object’s state changes as a result of events handled by the object
State
- A condition or situation in the life time of an object, during which, it satisfies some condition or performs some activity
- The state of an object is determined by :
- values of the attributes.
- relationships to other objects.
Event
- A significant occurrence in space and time
- Stimulus which can cause a state transition
- On the diagram, an event can be drawn using an operation name or by simply using an English phrase.
- Events can have arguments
Transition
- Relationship between two states, indicating that an object in the first state will enter the second state when an event occurs
- On the diagram, each transition is drawn as an arrow from the originating state to the succeeding state.
- Transitions can also be reflexive. Something may happen that causes an object to transition back to the state it is currently in.
Activity
- Ongoing non-atomic operation
Action
- Executable atomic operation
- An Entry Action is a behavior that occurs while the object is transitioning into the state.
- An Exit Action occurs as part of the transition out of a state
Guard condition
- Controls when a transition can or cannot occur.
- A guard condition is drawn along the transition line, after the event name, and enclosed in square brackets.
- Guard conditions are optional
A state diagram looks like a collection of vertices and arcs.
These diagrams serve to document the dynamic behavior of a class so that developers and analysts will have a clear understanding of its behavior.
Example
Exercise
A bank account object can be open, closed and overdrawn
Open – If balance is greater than zero
Closed – If customer has requested closure
Overdrawn – If balance is less than zero
On closure, remaining balance will be credited to customer•On overdraft, an e-mail notice will be sent to customer.
No comments:
Post a Comment
Note: only a member of this blog may post a comment.