NJIT Modeling Behavior in State Chart Diagrams Chapter 29 Rafael Mello.

15
NJIT Modeling Behavior in State Chart Diagrams Chapter 29 Rafael Mello

Transcript of NJIT Modeling Behavior in State Chart Diagrams Chapter 29 Rafael Mello.

Page 1: NJIT Modeling Behavior in State Chart Diagrams Chapter 29 Rafael Mello.

NJIT

Modeling Behavior in State Chart Diagrams

Chapter 29

Rafael Mello

Page 2: 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.

Page 3: NJIT Modeling Behavior in State Chart Diagrams Chapter 29 Rafael Mello.

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.

Page 4: NJIT Modeling Behavior in State Chart Diagrams Chapter 29 Rafael Mello.

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.

Page 5: NJIT Modeling Behavior in State Chart Diagrams Chapter 29 Rafael Mello.

Statechart Diagrams

initial Statestate

transition

event

A Statechart diagram shows the lifecycle of an object

Page 6: NJIT Modeling Behavior in State Chart Diagrams Chapter 29 Rafael Mello.

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.

Page 7: NJIT Modeling Behavior in State Chart Diagrams Chapter 29 Rafael Mello.

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.

Page 8: NJIT Modeling Behavior in State Chart Diagrams Chapter 29 Rafael Mello.

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.

Page 9: NJIT Modeling Behavior in State Chart Diagrams Chapter 29 Rafael Mello.

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:

Page 10: NJIT Modeling Behavior in State Chart Diagrams Chapter 29 Rafael Mello.

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.

Page 11: NJIT Modeling Behavior in State Chart Diagrams Chapter 29 Rafael Mello.

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.

Page 12: NJIT Modeling Behavior in State Chart Diagrams Chapter 29 Rafael Mello.

Additional Statechart Diagram Notation

Additional features UML notation for statechart diagram: Transition actions Transition guard condition Nested states

Page 13: NJIT Modeling Behavior in State Chart Diagrams Chapter 29 Rafael Mello.

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.

Page 14: NJIT Modeling Behavior in State Chart Diagrams Chapter 29 Rafael Mello.

Additional Statechart Diagram Notation (Cont.)

Example of Transition action and guard notation

Page 15: NJIT Modeling Behavior in State Chart Diagrams Chapter 29 Rafael Mello.

Additional Statechart Diagram Notation (Cont.)

Example of nested states