18
State Change Modelling

State Change Modelling. Aim: To introduce the concept and techniques for describing the changes in state that may occur to an object in its lifetime

  • View
    213

  • Download
    0

Embed Size (px)

Citation preview

State Change Modelling

State Change Modelling

• Aim: To introduce the concept and techniques for describing the changes in state that may occur to an object in its lifetime.

State Change Specification

● “A state change specification is a dynamic model that shows the different states that a single object passes through during its life in response to events, along with its responses and actions” (Dennis et al 2004)

● The state of an object is determined by the values of its attributes

● The modelling of object states is done with statechart - or state transition - diagrams– a graph consisting of states, events and transitions

● State models are built for each class that exhibits interesting dynamic behaviour

Example

Basic Elements

● State– a set of values that describe an object at a specific point in time

● e.g. when the object satisfies some condition● e.g. when the object performs some action● e.g. while the object waits for something to

happen– depicted by a state symbol – a rectangle with rounded corners

● labelled with a meaningful name– special states

● initial state (solid filled circle), final state (bull's eye)

Basic Elements

● Transitions– arrows connect states– labelled with a transition string– transitions are triggered by events

● change event: occurs when a condition (usually boolean) becomes true

– syntax: when '[' condition ']'● call event: occurs when an object receives a call for one

of its operations● signal event: occurs when an object receives a signal (asynchronous communication)● time event: caused by the passing of a period of time

Syntax of events

● Transition strings for call and signal events– event-signature '[' guard-condition ']' '/‘ action-expression

● event-signature – event-name '(' parameter-list ')'

● guard-condition – a boolean expression

● action-expression – is executed when an event triggers the transition to fire

– may comprise an action or sequence of actions

Event Example

Statechart for class Campaign

More Elements

● Optional activities and internal transitions– internal actions or activities associated with a state

● 'entry' '/' action-expression● 'exit' '/' action-expression● 'do' '/' activity-name '(' parameter-list')'● 'include' '/' substate

– a list of internal transitions● event-signature '[' guard-condition ']' '/' action-expression '^' send-clause● the send-clause syntax

– destination-expression '.' destinationevent- name '(' argument ',' ... ')'

Example

Menu Visible State for a DropDownMenu Object

More Elements

● A state may have nestedsubstates

– or-substate● a state has substates, but can only be in one substate at a time

– and-substate (concurrent substates)● a state may have many concurrent substates

● Used to manage complexity and keep diagrams simple

Nested Substates Example

The Active state with Concurrent Substates

Preparing Statechart: A Behavioural Approach

1. Examine all interaction diagrams that involve classes with heavy messaging

2. Identify the incoming messages that may correspond to events and identify the possible resulting states

3. Document these events and states on a statechart diagram

4. Elaborate the statechart as necessary5. Develop any nested statecharts6. Review the statechart to ensure consistency with use

cases7. Iterate steps 4, 5 and 68. Check the consistency of the statechart with the class

diagram, interaction diagrams and other statecharts

Consistency Checking

● Consistency rules

– every event in a statechart should appear as an incoming message

for the appropriate object in an interaction diagram

– every message in an interaction diagram corresponds to an

operation in a class diagram

– every action in the statechart should correspond to the execution of

an operation on the appropriate class

– every state in a statechart must be captured by an attribute in a class

diagram

– every outgoing message sent from a statechart must correspond to

an operation on another class

summary

• State models show the different states that a single object passes through during its life in response to events, along with its responses and actions

• Modelling state changes is done towards the end of theanalysis phase

• Object state specification– states, transitions, events, conditions, actions

• Always check for consistency between models• References

– Maciaszek, chapter 4, Bennett et al, chapter 11