PB007 Software Engineering I — Getting Dynamic, State Machine Diagram1 Getting Dynamic, State Machine Diagram PB007 Software Engineering I Lukáš Daubner daubner@mail.muni.cz PB007 Software Engineering I — Getting Dynamic, State Machine Diagram2 State Machine Diagram ̶ Models the dynamic behavior (life cycle) of one subject ̶ Class instantiation (Object) ̶ Use Case ̶ System ̶ Subsystem ̶ Component ̶ … ̶ Main components are: ̶ States ̶ Transitions ̶ Events State Event Transition PB007 Software Engineering I — Getting Dynamic, State Machine Diagram3 States State Machine Diagram ̶ Represents semantically important situation ̶ In case of (OOP) object, it is determined by attribute values, relations with others, and performed activity. Entry action Performed when entering the state Exit action Performed when exiting the state Internal activity Ongoing behavior while in the state Deferrable Trigger Event, which is registered but its processing is left for other states Internal Transition Transition, which is processed without exiting the sate PB007 Software Engineering I — Getting Dynamic, State Machine Diagram4 Transitions State Machine Diagram ̶ Defines how to get from one state to another ̶ Syntax: event [guard condition] / action ̶ Semantics: At the occurrence of event, if the guard condition holds, perform action and go to the new state. Event Condition (bool) Action PB007 Software Engineering I — Getting Dynamic, State Machine Diagram5 Events State Machine Diagram ̶ Stimulus on which the subject may react by changing the state or performing an operation. ̶ Types of events: ̶ Call event – Calling operation of the subject. ̶ Signal event – Asynchronous sending a receiving a signal between subjects ̶ Change event – Boolean expression. The event occurs when the value is changed from false to true. ̶ Time event – Event occur at a certain time t (when(t)) or after a certain time t (after(t)). PB007 Software Engineering I — Getting Dynamic, State Machine Diagram6 Events State Machine Diagram (excerpt from diagram) PB007 Software Engineering I — Getting Dynamic, State Machine Diagram7 Simple composite state Composite States ̶ Useful for simplifying the diagram ̶ Capturing inheritance between states ̶ Consist of a single region PB007 Software Engineering I — Getting Dynamic, State Machine Diagram8 Orthogonal composite state Composite States ̶ Capturing parallel behavior ̶ Consist of a two and more regions PB007 Software Engineering I — Getting Dynamic, State Machine Diagram9 State Machine Diagram in OOP world ̶ In our case, state machine diagram is used to represent lifecycle of an object ̶ Context of the diagram is only the instance of a class from design class diagram ̶ All methods and events must be supported by the design class diagram ̶ Initial transition means calling the constructor ̶ Final transition means deleting the object from system ̶ Object saves its state even outside main memory (persistence) PB007 Software Engineering I — Getting Dynamic, State Machine Diagram10 State Machine Diagram in OOP world PB007 Software Engineering I — Getting Dynamic, State Machine Diagram11 You gotta do what you gotta do Task for this week ̶ Process the feedback ̶ Choose a suitable object for modeling ̶ Something with non-trivial lifecycle ̶ Create a state machine diagram for this object ̶ Revise design class diagram if needed ̶ Do your part in peer review