State Diagram – Advanced Concepts
Communications between objects Objects communicate by sending messages to each other. Messages are realized by events and transitions in state diagram. The object that sends a message is said to generate an event. Modeled by the action associated with the transition The object that receives the message is said to realize / accept that event.
Communication between three state machines GUI object Open / generateAccountNumber(act) ^ Account.open(); Database.openAccount(act) Some State Some other State Account object open Initial Database object openAccount (act) / addAccount(act) Some State Communication between three state machines
Expanded syntax for transition A transition is specified using the following syntax in order to show the communication between the objects event-name (parameters) [guard] / action-sequence ^ send-clause where ‘send-clause’ is specified as object.event-name (parameters); …
Messages shown in state diagrams Remote Control On Off On Off On() Play Stop Off() Play() Stop() CD Player On Play On & Play Off On & Stop Off Stop Off
Simple and composite states A state is composite, in contrast to a simple state, if it has a decomposition UML Manual version 1.5 A composite state includes nested substates A diagram for a composite state has two or more sub-diagrams connected by simple and/or concurrent transitions The entry point of a substate is connected to the initial state of the substate The exit point of a substate is connected to all final states of the substate
Composite state with or-substates Running Forward Backward The states of a running car
Or-substates Also called orthogonal states in UML 2.0 The composite state has two or more mutually exclusive substates When the object is in the composite state, only one of the substates is active In the previous diagram, the running car will be in ‘forward’ state or in ‘backward’ state at any time but not in both Each substate can be explained by a separate state diagram
Composite state with and-substates Running Forward Backward Low Speed High Speed The states of a running car
And-substates Also called non-orthogonal states in UML 2.0 The composite state has two or more concurrent substates When the object is in the composite state, every one of the concurrent substates is active In the previous diagram, the running car will be in one of the four states: ‘forward & low speed’, ‘forward & high speed’, backward & low speed’ and ‘backward & high speed’ Each substate can be explained by a separate state diagram
Or-substates – Another Example Eject No CD loaded Power ON [no CD] Eject [CD in] Power OFF Power ON [CD in] CD loaded
Expanded state diagram No CD Loaded Eject CD drawer closed CD drawer open Power OFF Power ON [no CD] Eject [no CD] Eject Eject [CD in] CD loaded Power ON [CD in] CD playing Pause CD paused Pause or Play Power OFF Stop Stop CD stopped Play
And-substates – another example Student attending a course Incomplete Lab done Lab done Complete Lab 1 Complete Lab 2 passed Project done Complete Project Complete Final exam pass fail failed
Observation If there is a transition from any one of the substates that lead to a state outside the composite state, then all the other concurrent substates terminate prematurely The transition “fail” in the third substate illustrates this situation
State diagrams and specialization Inheritance mechanism allows to redefine only behaviors of a superclass and not the structure of the superclass The structure of a subclass must be the same or a superset of the structure of the superclass Every state of a superclass object is also a valid state of the subclass object The state diagram of a superclass can be inherited into the state diagram of a subclass
Composite State - Exercise Draw a composite state diagram indicating the states of two phones when both of them are in use. Hint: First identify the various values for the status of a single phone