Tuesday, July 31, 2007

Modeling a Statechart diagram

State - of an object is simply its current condition. That condition is reflected in the values of the attributes that describe the object.
Scope of the Statechart is the entire life of one object.
Statechart models the events that trigger a transition(change) from one state to another state.
An event or action corresponds to a message sent to the object asking or telling it to do something .
Describes the life of one object in terms of the events that trigger changes in the object's state. It identifies both the external events and internal events that can change the object's state.
we can derive a Statechart diagram from the interactions on a Sequence diagram.

Modeling object states and events
A simple state is modeled as a rounded rectangle with the state name inside.

Initial state - of an object is modeled as a solid dot with an arrow pointing to the first state.



Figure 10-2: Initial state notation.
final state - is modeled as a bull's-eye, a dot within a circle.

Modeling events and transitions
An event on a Statechart diargam corresponds to a message on a Sequence diagram.
Event notation is a label on an arrow connecting one state to another state, using a solid line with a stick arrowhead.

Within a Statechart diagram. an object doesn't need to know who send the event.
An object is only responsible for how it responds to the event.

Modeling change events


Figure 10-8: Deriving new states from the event parameters.




Figure 10-9: Revised Statechart diagram that improves cohesion and coupling.


Modeling a guard condition



Figure 10-10: Modeling a guard condition.


Modeling event actions
An action expression is the set of one or more actions triggered by an event.
It considered as an atomic task.
To model the action expression, place a forward slash after the event name followed by the name of the action or actions you want performed.



Figure 10-11: Modeling an event/action pair.

Internal transitions
We can add a internal transitions compartment to name compartment of the state icon. It reveals what the object can do while it is in a given state.


Figure 10-12: The expanded state icon.

The internal trasitions compartment contains information about actions, activities, and internal transitions specific to that state.

Modeling activities
Activities are processes performed within a state. An activity may be a group of separate tasks.


Figure 10-16: The expanded state icon with activities.

These activities will be performed from the time the object enters the state until the object leaves the state or the activity/ies finish.

Modeling Internal transitions

While an object is in a given state it may receive events that do not trigger a change in state, yet do trigger a response. An event that can be handled completely without a change in state is called an internal transition.


Figure 10-17: Internal transition.

There may be any number of internal transitions in a state. Each may have associated action expressions. Simply list them within the internal transitions compartment.

No comments: