NJIT Modeling Behavior in State Chart Diagrams Chapter 29 Rafael Mello
Introduction A State Diagram is drawn to show the life history of a reactive object. A reactive, event-driven, object is one whose behavior is best characterize by its response to events dispatched from outside its context. Objects are usually in a state, ex: Idle, until an event is trigger and makes the object transition from state to state. When that happens, its response usually depends on prior events.
Events and States Event – Is an occurrence that triggered the state. A telephone receiver is taken off the hook. State – Is the condition of a object at a specific time. A telephone is on “idle” state until it is taken from the hook.
Transitions Transition – Involves going from one state to the other when an event occurs. Transitions are label in form: Event [Guard] / Action When the event “off hook” occurs, transition the telephone from the “idle” state to the “active” state.
Statechart Diagrams initial State state transition event A Statechart diagram shows the lifecycle of an object
Statechart Diagrams (Cont.) The state diagram on the previous slide illustrates a simple telephone state chart diagram, with states, events and transitions. The states are shown in round rectangles. The transitions are shown with arrows, and the events are the labels in each transition.
Use Case Statechart Diagrams The Use Case Statechart diagram is used to describe the sequence of external events that is handled by a system described in a use case scope. Ex: In a Process Sale use case it is not permitted to perform a makeCreditPayment until the endSale event has happened.
Classes that benefit from Statechart Diagram In addition to Use Case and system design, the Statechart diagram can be used to describe object state behavior. Object can be state-independent or state- dependant. State-independent objects are objects that always respond the same way to an event. State-dependent objects are object that reacts different to events.
When to use Statechart Diagrams The next slide contains a list of common state- dependant objects that might be worth illustrating in a Statechart diagram:
Classes that benefit from Statechart Diagram Use Case – View as a class Stateful sessions – Server-side software objects Systems – classes representing the system Windows – window’s action “Edit-Copy” Controllers – GRASP controller objects Transactions – The way transaction respond to events Devices – Microwave oven, Radio Role Mutators – Classes that change its roles.
Illustrating External and Interval Events There are three types of events: External Event – Events caused by an outside actor, outside of the system’s boundary. Internal Event – Events caused by an internal action, inside the system’s boundary. Temporal Event – Events caused by a determined date or time clock.
Additional Statechart Diagram Notation Additional features UML notation for statechart diagram: Transition actions Transition guard condition Nested states
Additional Statechart Diagram Notation (Cont.) Transitions are what makes an action to fire, such as a method invocation. A transition also can have a Boolean test, such as a guard, that only happens if the test succeeds. Nested states represents substates. The substate inherits the transitions of its superstate.
Additional Statechart Diagram Notation (Cont.) Example of Transition action and guard notation
Additional Statechart Diagram Notation (Cont.) Example of nested states