2/25/2016COSC-4301-01, Lecture 191 Real-Time Systems, COSC-4301-01, Lecture 19 Stefan Andrei.

Slides:



Advertisements
Similar presentations
State Charts Mehran Najafi. Reactive Systems A reactive, event-driven, object is one whose behavior is best characterized by its response to events dispatched.
Advertisements

UML State chart/machine diagram State machine diagram is a behavior diagram which shows discrete behavior of a part of designed system through finite state.
1 Behavioral Modeling Chapter 8. 2 Key Ideas Behavioral models describe the internal dynamic aspects of an information system that supports business processes.
Object-Oriented Analysis and Design
Objectives Detailed Object-Oriented Requirements Definitions
1 Chapter 4 Dynamic Modeling and Analysis (Part I) Object-Oriented Technology From Diagram to Code with Visual Paradigm for UML Curtis H.K. Tsang, Clarence.
1 Chapter 4 Dynamic Modeling and Analysis (Part I) Object-Oriented Technology From Diagram to Code with Visual Paradigm for UML Curtis H.K. Tsang, Clarence.
5/24/2015CPSC , CPSC , Lecture 71 Software Engineering, CPSC , CPSC , Lecture 7.
Systems Analysis and Design in a Changing World, Fourth Edition
Slide 6B.1 Copyright © 2004 by The McGraw-Hill Companies, Inc. All rights reserved. An Introduction to Object-Oriented Systems Analysis and Design with.
Essentials of interaction diagrams Lecture 23 & 24.
Essentials of state and activity diagram Lecture 24.
State Machine Diagrams (State Chart in UML 1) Specifying Control (ref: Chapter 11 Bennett, Mc Robb and Farmer)
THE OBJECT-ORIENTED DESIGN WORKFLOW Statechart Diagrams.
UML Sequence Diagrams Eileen Kraemer CSE 335 Michigan State University.
Advanced Behavioral Modeling
Detailed Object-Oriented Requirements Definitions
Practical Object-Oriented Design with UML 2e Slide 1/1 ©The McGraw-Hill Companies, 2004 PRACTICAL OBJECT-ORIENTED DESIGN WITH UML 2e Chapter 10: Statecharts.
Case Study: Class Extraction.
Chapter 7: The Object-Oriented Approach to Requirements
State and Sequence Diagrams Modelling dynamic information So far we have seen: Use Case Diagrams – requirements capture, interface.
State Machine Diagram Chapter 10. State Machine Diagram Used to describe system behavior.
Lecture 4 Finite State Machine CS6133 Software Specification and Verification.
Chapter 10 State Machine Diagrams
Object-Oriented Software Engineering Practical Software Development using UML and Java Chapter 8: Modelling Interactions and Behaviour.
State Diagrams / System Sequence Diagrams (SSDs)
מידול התנהגותי 1. Today’s Session Sequence Diagrams State Machines 2.
1 Object-Oriented Modeling Using UML (2) CS 3331 Fall 2009.
NJIT Modeling Behavior in State Chart Diagrams Chapter 29 Rafael Mello.
The Object-Oriented Approach to Requirements
4 2009/10 Object Oriented Technology 1 Topic 4: The Object-Oriented Approach to Requirements Adopted from: Ch.7 The Object-Oriented Approach to Requirements.
Systems Analysis and Design in a Changing World, Fifth Edition
Practical Object-Oriented Design with UML 2e Slide 1/1 ©The McGraw-Hill Companies, 2004 PRACTICAL OBJECT-ORIENTED DESIGN WITH UML 2e Chapter 9: Interaction.
Behavioral diagrams Lecture p4 T120B pavasario sem.
CSC 395 – Software Engineering Lecture 13: Object-Oriented Analysis –or– Let the Pain Begin (At Least I’m Honest!)
Object-Oriented Modeling Using UML CS 3331 Section 2.3 of Jia 2003.
1 Modeling interactions and behavior Lecturer Dr. Mai Fadel.
Requirements as Usecases Capturing the REQUIREMENT ANALYSIS DESIGN IMPLEMENTATION TEST.
Behavioral Modeling Chapter 8.
CSIS3600 System Analysis and Design Statechart Diagrams.
7 Systems Analysis and Design in a Changing World, Fifth Edition.
Course Instructor: Kashif Ihsan 1. Chapter # 3 2.
1 Kyung Hee University Diagram Editor : Design View Spring 2001.
1 Kyung Hee University Statecharts Spring Kyung Hee University Specifying Objects’ Behaviour  Interaction diagrams show message-passing behaviour.
7. 2Object-Oriented Analysis and Design with the Unified Process Objectives  Detailed Object-Oriented Requirements Definitions  System Processes—A Use.
OMT Modeling 1. Object Model : presented by the object model and the data dictionary. 2. Dynamic Model: presented by the state diagrams and event flow.
Systems Analysis and Design in a Changing World, Fourth Edition
States.
CS3773 Software Engineering Lecture 06 UML State Machines.
State Chart diagram Week objective Describe State chart Diagrams in Dynamic Modelling 2.
SOFTWARE DESIGN AND ARCHITECTURE LECTURE 26. Review UML behavioral Diagrams – Sequence diagram.
INFO 620Lecture #71 Information Systems Analysis and Design Design Class Diagrams and others INFO 620 Glenn Booker.
Practical Object-Oriented Design with UML 2e Slide 1/1 ©The McGraw-Hill Companies, 2004 PRACTICAL OBJECT-ORIENTED DESIGN WITH UML 2e Chapter 10: Statecharts.
Modeling Object Lifecycles and State-Dependent Behavior ©SoftMoore ConsultingSlide 1.
Practical Object-Oriented Design with UML 2e Slide 1/1 ©The McGraw-Hill Companies, 2004 PRACTICAL OBJECT-ORIENTED DESIGN WITH UML 2e Chapter 6: Restaurant.
7 Systems Analysis – ITEC 3155 The Object Oriented Approach – Use Cases.
1 7 Systems Analysis and Design in a Changing World, 2 nd Edition, Satzinger, Jackson, & Burd Chapter 7 The Object-Oriented Approach to Requirements.
1 Object Oriented Analysis System modeling = Functional modeling + Object modeling + Dynamic modeling Functional modeling = Use cases Object modeling =class.
UML Review: State Machines. Sept. 17, 2003Lecture 5: CS660 Fall Overview States Transitions Activities Modeling object lifeline Creating well-structured.
Systems Analysis and Design in a Changing World, Fourth Edition
State Machine Model.
State Machine Diagrams
Unified Modeling Language
State Machine Diagrams
CS251 – Software Engineering Lectures 11 State Diagrams
States.
Object Oriented System Design
States.
CIS 375 Bruce R. Maxim UM-Dearborn
Modeling Behavior in Statechart Diagrams
Presentation transcript:

2/25/2016COSC , Lecture 191 Real-Time Systems, COSC , Lecture 19 Stefan Andrei

2/25/2016 COSC , Lecture 19 2 Reminder of the last lecture Model checking of finite-state systems

2/25/2016 COSC , Lecture 19 3 Overview of This Lecture Visual formalism, statecharts, and STATEMATE

2/25/2016 COSC , Lecture 19 4 Finite-state machine vs Statechart Lacks modularity Exponential state explosion Cannot specify absolute time and time intervals Modular and hierarchical features Refinement: a state decomposed into lower-level states Clustering: set of states combined into a higher- level state

2/25/2016 COSC , Lecture 19 5 Applications of Statecharts Specifying reactive systems.  Reactive systems are complex-driven mechanisms that interact with discrete occurrences in the environment in which they are embedded.  Examples of reactive systems: Real-time computer systems, communication devices, control plants, VLSI circuits, airplane avionics.  The reactive behavior of real-time systems cannot be captured by specifying the outputs for every possible set of inputs.  Instead, this behavior has to be described by specifying the relationship of inputs, outputs, the system state over time.

2/25/2016 COSC , Lecture 19 6 Object Behavior The behavior of an object is defined by its reaction to messages at any point in execution. Some object behaviors can be studied by:  Object Diagram, OR  Interaction Diagram Not sufficient:  Cannot model all possible scenarios, e.g., only specific sequence of messages are studied.  Only model some legal (possible) states - show how an object behaves in particular interactions.  We need to know about illegal or impossible states to plan for them.

2/25/2016 COSC , Lecture 19 7 Specifying Behaviour in UML Different notation is needed to summarize the overall behaviour of objects. UML defines a statechart for this purpose. Complement interaction diagrams for understanding the dynamic behaviour of system:  Interaction Diagram: Models some inter-object messages with well defined order during a short duration.  Statechart: Models the entire lifetime of a single object, specifying all possible sequences of messages and responses.

2/25/2016 COSC , Lecture 19 8 State-dependent Behaviour Objects respond differently to the same stimulus/events at different times. Can be modelled by defining a state machine:  It has a set of states: an object can be in one state at any time; the state it is in determines how it responds to events.  It has a set of transitions: an event can cause the object to move from one state to another.

2/25/2016 COSC , Lecture 19 9 CD Player: An Example Behaviour of a simple CD player:  A drawer to hold the CD;  Control interface with 3 buttons: Load button: the drawer will open if it was shut and will shut if it was open; Stop button: the player will stop playing. If there is no CD, there is no effect; Play button: the CD will be played. If the drawer is open, the drawer shuts before playing starts.

2/25/2016 COSC , Lecture UML Statechart Semantic A statechart defines the behaviour of instances of a given class. It shows:  The possible states of an object;  The events it can detect;  Its response to those events. An object is in one active state at a time:  Events may be received at any time, which can trigger a transition to the next active state;  If an Event only causes a loop on a state (i.e., no change of an active state), the transition is known as self-transition.

2/25/2016 COSC , Lecture Statechart: Deciding States Identifying separate states:  Informal principle: States S1 and S2 are separate if an object in state S1 responds differently to at least one event from the way it responds to that event in state S2. Syntax:  States: rounded rectangles with the name of the state ( ). Example:  There are 3 states for the CD player: Closed, Playing, Open. StateName

2/25/2016 COSC , Lecture Statechart: Identifying Events Events are usually external stimulus:  E.g., messages that can be sent to an object;  Internal stimulus will be covered later in the lecture. Events usually cause an object to change state:  Moving from one state to another is known as transition;  Events that causes transition are known as trigger;  Events can optionally carry data (similar to message parameter). Syntax:  An arrow with the trigger attached ( ). Example:  There are three events for the CD Player : load, play, stop. trigger

2/25/2016 COSC , Lecture CD Player: Statechart Ver. 1 Statechart State: The Open state. Transition: From Closed state to Open state triggered by load event.  Figure 10.1 from [Priestley; 2004], page 210

2/25/2016 COSC , Lecture Initial and Final States To specify the first active state when an object is created/initialized:  Use Initial State: A transition leading from the initial state indicates the first active state. No event should be written on a transition from an initial state. Syntax: a black disc ( ). To model the destruction of an object:  Use Final State: Represent the end of flow, i.e., the object no longer exists. May correspond to actual destruction for software object. Syntax: a circled black disc ( ).

2/25/2016 COSC , Lecture CD Player: Statechart Ver. 2 Statechart Initial State: CD Player switched on Final State: Switched Off the CD Player  Figure 10.2 from [Priestley; 2004], page 212

2/25/2016 COSC , Lecture Non-Deterministic System When two or more transitions leading from a state share the same trigger:  No way to distinguish between them;  Randomly choose one of them;  The same history of events may end up in a different state;  Known as non-deterministic system. Can be removed by adding information to distinguish between transitions with the same trigger.

2/25/2016 COSC , Lecture CD Player: Non Deterministic Example Statechart This transition should be for no CD inside. This transition should be used when there is a CD inside. In real-life, a CD player will not play if there is no CD inside. Statechart Ver. 2 does not describe this. Correct Behaviour:  When the play event is detected, the CD Player should remain in the Closed state if there is no CD inside. Resulting Statechart (partial), Figure 10.3 from [Priestley; 2004], page 213:

2/25/2016 COSC , Lecture Guard Condition Although the two transitions are meant for different scenarios, the statechart does not distinguish among the two, resulting in non-deterministic behavior. The non-determinism can be removed if we can specify the condition that determine the correct transition to use. Syntax: trigger [guard_condition] Semantics:  If a transition has a guard condition, it can only fire if that transition is evaluated to true ;  If all guard conditions are false and there is no unguarded transition, the event will be ignored.  Usually, only one condition is true (determinism).

2/25/2016 COSC , Lecture CD Player: Statechart Ver. 3 Statechart Guard Condition Note that guard conditions are also added to transitions leading from the Open state. What do they represent?  Figure 10.4 from [Priestley; 2004], page 213

2/25/2016 COSC , Lecture Actions A state can have actions triggered. There are three ways an action can be triggered:  By an event;  By entering a state;  By leaving a state. An action triggered by an event takes place in response to that event:  Syntax: Trigger [Guard_Condition] /action Example:  The CD drawer will be closed when play is detected in the Open state.

2/25/2016 COSC , Lecture CD Player: Statechart Ver. 4 Statechart Action triggered by Event  Figure 10.5 from [Priestley; 2004], page 215

2/25/2016 COSC , Lecture Action: Entering/Exiting a State An action can be triggered as soon as the state is entered. Useful to capture actions that must be performed regardless the transition used to arrive at the state. Syntax:  Write in a compartment in the state box: entry/action Similarly, an action can be performed just before leaving a state. Syntax:  Write in a compartment in the state box: exit/action

2/25/2016 COSC , Lecture CD Player: Statechart (partial) Statechart Action triggered by entering a state. Action triggered by leaving a state. Question: What happened when the play button is pressed during CD playing?  Figure 10.6 from [Priestley; 2004], page 215

2/25/2016 COSC , Lecture Action and Activity Properties of Actions:  Short, self-contained processing;  Finished “instantaneously”;  Cannot be interrupted by events. An “action” that does not conform to the above is termed as activity instead. Property of Activities:  Performed during a state;  Carry out for an extended period of time;  Can be interrupted by events. Syntax:  Write in a compartment of the state box: do/activity

2/25/2016 COSC , Lecture CD Player: Activity Example Question: When the play track activity is being performed, what happen if the stop button is pressed? Statechart (Partial) Activity performed during the Playing state.  Figure 10.7 from [Priestley; 2004], page 216

2/25/2016 COSC , Lecture Completion Transition As well as being interrupted by events, some activities will come to an end of their own accord. If an activity completes uninterrupted, then it can trigger a completion transition.  these are transitions without event labels. Multiple completion transitions can be distinguished by guard conditions. Example:  When the play track activity is completed: If it is the last track, go to Closed state; If it is not the last track, play the next track.

2/25/2016 COSC , Lecture CD Player: Completion Transition Example Statechart (Partial) Completion Transition: Play the next track Completion Transition: No more track. Stop playing  Figure 10.8 from [Priestley; 2004], page 217

2/25/2016 COSC , Lecture Internal Transition These are transitions that leave the object in the same state but does not trigger the entry and exit actions: A self-transition is not appropriate. Why? Use an Internal Transition which does not trigger the entry and exit action. Syntax:  Write in a compartment of the state box: event/action Example:  Suppose we add an info button for the CD Player to display the remaining playing time for current track.

2/25/2016 COSC , Lecture CD Player: Internal Transition Statechart – Internal Transition (Partial) Statechart – Self- transition(Partial) Info /display time Compare the two different ways to model the info button.  Figure 10.9 from [Priestley; 2004], page 218

2/25/2016 COSC , Lecture Composite State States that share similar behavior can be grouped into a Composite State to simplify the statechart. Composite State:  Syntax similar to simple state;  Contains a number of substates;  When a composite state is active, exactly one of the substate must be active;  Transitions can lead away from a composite state as well as any of its substates. Example:  CD Player: the response to the play event is similar during the Open or Closed states.

2/25/2016 COSC , Lecture CD Player: Composite State Statechart Composite State Sub-State Transition shared by all substates Transition specific to one substate  Figure from [Priestley; 2004], page 219

2/25/2016 COSC , Lecture Composite State: Additional Property A composite state is just like a simple state:  Can have Entry/Exit actions;  Can have extended activity. A composite state is also like a mini-statechart:  Can have an Initial State to indicate the default substate if a transition terminates at boundary of a composite state;  Can have a Final State, which is triggered when ongoing activity within the state has finished. Transitions:  Leading away from a composite state apply to all substates;  Arrive at composite state go to the default/initial state;  Can cross composite state boundaries.

2/25/2016 COSC , Lecture CD Player: pause button Pressing the pause button causes playing to be interrupted; When the button is pressed again, playing continues from the position where it was paused, Figure from [Priestley; 2004], page 220. Statechart Only triggers if the Composite State is entered. As there is no entry action, reentering the Playing substate will not restart the track.

2/25/2016 COSC , Lecture History State When a composite state is entered, it begins at the initial state or directly transits into one of the substates. Sometimes, it is useful to re-enter a composite state at a point at which it was left.  Re-enter the last active substate. Indicate this using the History State.  Transitions arriving at the History State activates the last active substate. If there is no last active substate, a default state can be indicated by an unlabelled transition from History State. Syntax:  A circled ‘H’ ( ) H

2/25/2016 COSC , Lecture CD Player: History State Suppose that re-pressing play button:  During Playing: restart and play the current track;  During Paused: restart the current track but remain paused, Figure from [Priestley; 2004], page 221. Statechart Make use of History State to model the behavior correctly. Question: Does the statechart on slide 31 model this correctly?

2/25/2016 COSC , Lecture CD Player: Final Version Statechart Statechart  Figure from [Priestley; 2004], page 222

2/25/2016 COSC , Lecture Statechart Notation Summary Event(param) [condition] /action Entry /action Exit /action Do /activity Event /action State Name H State Transition and Trigger Initial State Final State History State

2/25/2016 COSC , Lecture Steps for Constructing Statechart 1. Identify the objects that have complex behavior; 2. Determine the initial and final states of the object; 3. Identify the events that affect the entity; 4. Working from the initial state, trace the impact of events and identify the intermediate states; 5. Identify any entry and exit actions on the states; 6. Expand states into a composite state if necessary; 7. Check that actions in the state are supported by operation (method); 8. Refine the class if necessary. Another example of constructing Statechart: “Ticket Machine”.

2/25/2016 COSC , Lecture Creating a Statechart How information from interaction diagrams can be used to derive statecharts? It can be hard to identify all necessary states. Statecharts can be developed incrementally:  consider individual sequences of events received by an object;  these might be specified on interaction diagrams;  start with a statechart for one interaction;  add states as required by additional interactions.

2/25/2016 COSC , Lecture Ticket Machine Consider a ticket machine with two events:  select a ticket type;  enter a coin. Basic interaction is to select a ticket and then enter coins.  model this as a ‘linear’ statechart, Figure from [Priestley; 2004], page 224. Problems:  It defines only one transaction, whereas the ticket machine is able to carry out repeated transactions;  It shows only 3 coins, but this number should be arbitrary.

2/25/2016 COSC , Lecture Refining the Statechart This can be improved by adding ‘loops’:  the number of coins entered will vary: entry will continue until the ticket is paid for;  the whole transaction can be repeated. State ‘Idle’: no transaction is in progress, Figure from [Priestley; 2004], page 225.

2/25/2016 COSC , Lecture Adding Another Interaction Suppose the requirements allow the user to enter a coin before selecting a ticket. A ‘coin’ transition from the ‘Idle’ state is needed to handle this event.  this transition can’t go to the ‘Paying for Ticket’ state as the ticket is not yet selected.  so a new state ‘Inserting Coins’ is required. The statechart is thus built up step-by-step.

2/25/2016 COSC , Lecture Adding a Second Interaction If all coins are entered before ticket selected, Figure from [Priestley; 2004], page 226:

2/25/2016 COSC , Lecture Integrating the Interactions Suppose the requirements allow the user to enter some coins before selecting a ticket and the rest after that. In fact, events can occur in any sequence, Figure from [Priestley; 2004], page 227:

2/25/2016 COSC , Lecture Time Events Suppose the ticket machine times out after 30 seconds.  we need to fire a transition that is not triggered by a user-generated event;  UML defines time events to handle these cases.  Example: a transition will fire 30 seconds after the ‘no ticket selected’ state is entered, Figure from [Priestley; 2004], page 228.

2/25/2016 COSC , Lecture Activity States Both ‘No Ticket Selected’ and ‘Ticket Selected’ should check if the machine is able to return any change that is required. Efficient solution: activity states! Activity states defines periods of time when the object is carrying out internal processing.  unlike normal activities, these cannot be interrupted by external events;  only completion transitions leading from them;  useful for simplifying the structure of complex statecharts.

2/25/2016 COSC , Lecture Returning Change Note that activity as a property of state (slide 23) is not the same as activity states. Use an activity state to calculate change, Figure from [Priestley; 2004], page 229.

2/25/2016 COSC , Lecture Ticket Machine Statechart It incorporates ‘Pressing Cancel’ in the middle of a transaction. The composite state ‘Transaction’ reduces the number of statechart transitions, Figure from [Priestley; 2004], page 230. Statechart

2/25/2016 COSC , Lecture Summary Visual formalism, statecharts, and STATEMATE:  Statecharts

2/25/2016 COSC , Lecture Reading suggestions Chapter 5 of [Cheng; 2002]; Chapter 10 of [Priestley; 2004], where this is:  M. Priestley: Practical Object-Oriented Design with UML. Second Edition, 2004, ISBN:

2/25/2016 COSC , Lecture Coming up next Visual formalism and STATEMATE (next lecture) Chapter 5 of [Cheng; 2002]

2/25/2016 COSC , Lecture Thank you for your attention! Questions?