University of Toronto Department of Computer Science © 2004-5 Steve Easterbrook. This presentation is available free for non-commercial use with attribution.

Slides:



Advertisements
Similar presentations
UML State Machine Diagrams and Modeling
Advertisements

Nested state diagrams:Problems with flat state diagram
Models of Concurrency Manna, Pnueli.
CS6133 Software Specification and Verification
5/24/2015CPSC , CPSC , Lecture 71 Software Engineering, CPSC , CPSC , Lecture 7.
Embedded Systems Details. Object Model: Four main system objects or classes Controller object might be made up of several controllers is the brains of.
Using UML, Patterns, and Java Object-Oriented Software Engineering Chapter 5, Analysis: Dynamic Modeling.
Dillon: CSE470:DYN & FUNC MODELLING1 Dynamic Model l Show the temporal order of operations l Control model »Show the sequence of operations that occur.
© Betty HC Cheng. This presentation is available free for non-commercial use with attribution under a creative commons license. Acknowledge: S.
State Machine Diagrams (State Chart in UML 1) Specifying Control (ref: Chapter 11 Bennett, Mc Robb and Farmer)
University of Toronto Department of Computer Science © Steve Easterbrook. This presentation is available free for non-commercial use with attribution.
THE OBJECT-ORIENTED DESIGN WORKFLOW Statechart Diagrams.
State Change Modelling. Aim: To introduce the concept and techniques for describing the changes in state that may occur to an object in its lifetime.
Advanced Behavioral Modeling
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.
SE-565 Software System Requirements More UML Diagrams.
CS451 Introduction to Software Engineering Behavioral Modeling.
Chapter 5 – System Modeling
Lecture 4 Finite State Machine CS6133 Software Specification and Verification.
Timed UML State Machines Ognyana Hristova Tutor: Priv.-Doz. Dr. Thomas Noll June, 2007.
Chapter 10 State Machine Diagrams
Real-Time Systems time dependent control oriented driven by events rather than data.
UML Notations in CommonKADS Activity diagrams State diagrams Class diagrams Use-case diagrams.
1 Object-Oriented Modeling Using UML (2) CS 3331 Fall 2009.
Software Engineering 1 Object-oriented Analysis and Design Chap 29 UML State Machine Diagrams and Modeling.
Fall 2010 CS4310 Requirements Engineering UML: Dynamic Modeling Dr. Guoqiang Hu Department of Computer Science UTEP 1.
State Modeling.
1 Software Engineering Dr. K. T. Tsang Lecture 8 State modeling
University of Toronto Department of Computer Science © Steve Easterbrook. This presentation is available free for non-commercial use with attribution.
Behavioral diagrams Lecture p4 T120B pavasario sem.
Object-Oriented Modeling Using UML CS 3331 Section 2.3 of Jia 2003.
Session 22 Modeling the Extended Features of the Statechart Written by Thomas A. Pender Published by Wiley Publishing, Inc. October 27, 2011 Presented.
University of Toronto Department of Computer Science © Steve Easterbrook. This presentation is available free for non-commercial use with attribution.
1 State Modeling  Events  States  Transitions and Conditions  State Diagrams  State Diagram Behavior  Practical Tips.
CSIS3600 System Analysis and Design Statechart Diagrams.
1 A Student Guide to Object- Oriented Development Chapter 7 State Diagrams.
University of Toronto at Scarborough © Kersti Wain-Bantin CSCC40 state charts 1 object states an object state is a condition or situation during the life.
Information System Design IT60105
Communicating Real-Time State Machines (CRSM) State machines that communicate synchronously Unique unidirectional channels are used for the communication.
1 Kyung Hee University Statecharts Spring Kyung Hee University Specifying Objects’ Behaviour  Interaction diagrams show message-passing behaviour.
UML Discussion on State Machines Perfectly static system is intensely uninteresting Because nothing ever happens.
Dynamic Models. Outline Dynamic Models Statecharts –States –Transitions –Composite states Interaction Diagrams –Sequence Diagrams The time order of interactions.
State Modeling. Introduction A state model describes the sequences of operations that occur in response to external stimuli. As opposed to what the operations.
States.
UML: State Chart Diagrams
CS3773 Software Engineering Lecture 06 UML State Machines.
Dynamic Modeling Grady Booch, James Rumbaugh, and Ivar Jacobson, The Unified Modeling Language User Guide, 2 nd edition, Addison Wesley, 2005.
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.
Dynamic Models - Page L M.E. Fayad Lesson 30: Dynamic Models Object- Oriented Modeling & Application s.
2/25/2016COSC , Lecture 191 Real-Time Systems, COSC , Lecture 19 Stefan Andrei.
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.
The Dynamic Analysis Model StateCharts Prof. Hany H. Ammar, CSEE, WVU, and Dept. of Computer Science, Faculty of Computers and Information, Cairo University.
York University Department of Computer Science © Castro, Mylopoulos and Easterbrook Lecture 11: Modelling “State”  What is State?  statespace.
State Modeling. Introduction A state model describes the sequences of operations that occur in response to external stimuli. As opposed to what the operations.
1 Object Oriented Analysis System modeling = Functional modeling + Object modeling + Dynamic modeling Functional modeling = Use cases Object modeling =class.
State Machine Model.
State Machine Diagram.
Marlon Dumas Institute of Computer Science
Static and Dynamic Modeling Using UML
Object Oriented Modeling and Design
UML State Diagrams.
CS251 – Software Engineering Lectures 11 State Diagrams
States.
Object Oriented System Design
Chapter 5 state Modeling
Marlon Dumas Institute of Computer Science
States.
UML Diagrams: StateCharts The Dynamic Analysis Model
Modeling Behavior in Statechart Diagrams
Presentation transcript:

University of Toronto Department of Computer Science © Steve Easterbrook. This presentation is available free for non-commercial use with attribution under a creative commons license. 1 Lecture 15: Modelling “State” Ü What is State?  statespace for an object  concrete vs. abstract states Ü Finite State Machines  states and transitions  events and actions Ü Modularized State machine models: Statecharts  superstates and substates  Guidelines for drawing statecharts

University of Toronto Department of Computer Science © Steve Easterbrook. This presentation is available free for non-commercial use with attribution under a creative commons license. 2 Getting objects to behave Ü All objects have “state”  The object either exists or it doesn’t  If it exists, then it has a value for each of its attributes  Each possible assignment of values to attributes is a “state”  (and non-existence of the object is also a state) Ü E.g. For a stack object empty1 item Push() Pop() new() 2 items3 items4 items Push() Pop() … Top()

University of Toronto Department of Computer Science © Steve Easterbrook. This presentation is available free for non-commercial use with attribution under a creative commons license. 3 empty1 item Push() Pop() new() 2 items3 items Push() Pop() Top() What does the model mean? Ü Finite State Machines  There are a finite number of states (all attributes have finite ranges)  E.g. imagine a stack with max length = 3  The model specifies a set of traces  E.g. new();Push();Push();Top();Pop();Push()…  E.g. new();Push();Pop();Push();Pop()…  There may be an infinite number of traces (and traces may be of infinite length)  The model excludes some behaviours  E.g. no trace can start with a Pop()  E.g. no trace may have more Pops than Pushes  E.g. no trace may have more than 3 Pushes without a Pop in between

University of Toronto Department of Computer Science © Steve Easterbrook. This presentation is available free for non-commercial use with attribution under a creative commons license. 4 Abstraction Ü The state space of most objects is enormous  State space size is the product of the range of each attribute  E.g. object with five boolean attributes: states  E.g. object with five integer attributes: (maxint) 5 +1 states  E.g. object with five real-valued attributes: …?  If we ignore computer representation limits, the state space is infinite Ü Only part of that state space is “interesting”  Some states are not reachable  Integer and real values usually only vary within some relevant range  Often, we’re only interested in certain thresholds:  E.g. for Age, we may be interested in age 65  E.g. for Cost, we may want to distinguish cost≤budget, cost=0, cost>budget, and cost>(budget+10%)

University of Toronto Department of Computer Science © Steve Easterbrook. This presentation is available free for non-commercial use with attribution under a creative commons license. 5 Collapsing the state space empty1 item Push() Pop() new() 2 items3 items4 items Push() Pop() … Top() emptynot empty Push() Pop() [sc=1] new() Pop() [sc>1] Top()  The abstraction usually permits more traces  E.g. this model does not prevent traces with more pops than pushes  But it still says something useful

University of Toronto Department of Computer Science © Steve Easterbrook. This presentation is available free for non-commercial use with attribution under a creative commons license. 6 What are we modelling? (D) Observed states of an application domain entity?  E.g. a phone can be idle, ringing, connected, …  Model shows the states an entity can be in, and how events can change its state  This is an indicative model (R) Required behaviour of an application domain entity?  E.g. a telephone switch shall connect the phones only when the callee accepts the call  Model distinguishes between traces that are desired and those that are not  This is an optative model (S) Specified behaviour of a machine domain entity?  E.g. when the user presses the ‘connect’ button the incoming call shall be connected  Model specifies how the machine should respond to input events  This is an optative model, in which all events are shared phenomena Application Domain Machine Domain D - domain properties R - requirements C - computers P - programs

University of Toronto Department of Computer Science © Steve Easterbrook. This presentation is available free for non-commercial use with attribution under a creative commons license. 7 Is this model indicative or optative? idleconnectedringing dial tone busy on hook off hook Dial [callee busy] Dial [callee idle] Callee accepts Callee disconnects

University of Toronto Department of Computer Science © Steve Easterbrook. This presentation is available free for non-commercial use with attribution under a creative commons license. 8 the world vs. the machine :person age havebirthday() childadultsenior havebirthday() [age = 18] havebirthday() [age = 65] havebirthday() [age < 18] havebirthday() [age < 65] havebirthday() child adult senior when [thisyear-birthyear>18] when [thisyear-birthyear>65] blank deceased recordBirth() /setDOB() recordDeath() /setDateofDeath() :person dateOfBirth dateOfDeath recordBirth() setDOB() recordDeath() setDateofDeath()

University of Toronto Department of Computer Science © Steve Easterbrook. This presentation is available free for non-commercial use with attribution under a creative commons license. 9 StateCharts Ü Notation:  States  “interesting” configurations of the values of an object’s attributes  may include a specification of action to be taken on entry or exit  States may be nested  States may be “on” or “off” at any given moment  Transitions  Are enabled when the state is “on”; disabled otherwise  Every transition has an event that acts as a trigger  A transition may also have a condition (or guard)  A transitions may also cause some action to be taken  When a transition is enabled, it can fire if the trigger event occurs and it guard is true  Syntax: event [guard] / action  Events  occurrence of stimuli that can trigger an object to change its state  determine when transitions can fire

University of Toronto Department of Computer Science © Steve Easterbrook. This presentation is available free for non-commercial use with attribution under a creative commons license. 10 Superstates OR superstates  when the superstate is “on”, only one of its substates is “on” AND superstates (concurrent substates)  When the superstate is “on”, all of its states are also “on”  Usually, the AND substates will be nested further as OR superstates Ü States can be nested, to make diagrams simpler  A superstate consists of one or more states.  Superstates make it possible to view a state diagram at different levels of abstraction. employed probationaryfull employed on payroll assigned to project after [6 months]

University of Toronto Department of Computer Science © Steve Easterbrook. This presentation is available free for non-commercial use with attribution under a creative commons license. 11 Off-hook Superstates example idleconnectedringing dial tone busy on hook off hook Dial [callee busy] Dial [callee idle] Callee accepts Callee disconnects idleconnectedringing dial tone busy on hook off hook Dial [callee busy] Dial [callee idle] Callee accepts Callee disconnects

University of Toronto Department of Computer Science © Steve Easterbrook. This presentation is available free for non-commercial use with attribution under a creative commons license. 12 adult single coupled A more detailed example childworking ageseniorunmarriedmarrieddivorcedwidowedseparateddeceased

University of Toronto Department of Computer Science © Steve Easterbrook. This presentation is available free for non-commercial use with attribution under a creative commons license. 13 States in UML Ü A state represents a time period during which  A predicate is true  e.g. (budget - expenses) > 0,  An action is being performed, or an event is awaited:  e.g. checking inventory for order items  e.g. waiting for arrival of a missing order item Ü States can have associated activities:  do/activity  carries out some activity for as long as the state is “on”  entry/action and exit/action  carry out the action whenever the state is entered (exited)  include/stateDiagramName  “calls” another state diagram, allowing state diagrams to be nested

University of Toronto Department of Computer Science © Steve Easterbrook. This presentation is available free for non-commercial use with attribution under a creative commons license. 14 Events in UML Ü Events are happenings the system needs to know about  Must be relevant to the system (or object) being modelled  Must be modellable as an instantaneous occurance (from the system’s point of view)  E.g. completing an assignment, failing an exam, a system crash  Are implemented by message passing in an OO Design Ü In UML, there are four types of events:  Change events occur when a condition becomes true  denoted by the keyword ‘when’  e.g. when[balance < 0]  Call events occur when an object receives a call for one of its operations to be perfomed  Signal events occur when an object receives an explicit (real-time) signal  Elapsed-time events mark the passage of a designated period of time  e.g. after[10 seconds]

University of Toronto Department of Computer Science © Steve Easterbrook. This presentation is available free for non-commercial use with attribution under a creative commons license. 15 Checking your Statecharts Ü Consistency Checks  All events in a statechart should appear as:  operations of an appropriate class in the class diagram  All actions in a statechart should appear as:  operations of an appropriate class in the class diagram and Ü Style Guidelines  Give each state a unique, meaningful name  Only use superstates when the state behaviour is genuinely complex  Do not show too much detail on a single statechart  Use guard conditions carefully to ensure statechart is unambiguous  Statecharts should be deterministic (unless there is a good reason) Ü You probably shouldn’t be using statecharts if:  you find that most transitions are fired “when the state completes”  many of the trigger events are sent from the object to itself  your states do not correspond to the attribute assignments of the class