Statecharts Slide: 1. Objectives Learn the concepts for modeling object states Learn Statechart notation to depict object state models Do some modelling…

Slides:



Advertisements
Similar presentations
State Diagram 1. State diagram: Shows the behavior of one object. They describe all of the possible states that a particular object can get into and how.
Advertisements

NCKU EE RTES LAB.1 Unified Modeling Language - Events and State Machines.
State Charts Mehran Najafi. Reactive Systems A reactive, event-driven, object is one whose behavior is best characterized by its response to events dispatched.
Karolina Muszyńska Based on: S. Wrycza, B. Marcinkowski, K. Wyrzykowski „Język UML 2.0 w modelowaniu SI”
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.
ESE Einführung in Software Engineering 7. Modeling Behaviour Prof. O. Nierstrasz.
Introduction to Software Engineering 7. Modeling Behaviour.
© 2006 ITT Educational Services Inc. SE350 System Analysis for Software Engineers: Unit 9 Slide 1 Appendix 3 Object-Oriented Analysis and Design.
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.
Using UML, Patterns, and Java Object-Oriented Software Engineering Chapter 5, Analysis: Dynamic Modeling.
State Machine Diagrams (State Chart in UML 1) Specifying Control (ref: Chapter 11 Bennett, Mc Robb and Farmer)
1 CS/CPE 426 Senior Projects Chapter 21: State Machines Chapter 22:Advanced State Machines [Arlow and Neustadt 2005] March 24, 2009.
THE OBJECT-ORIENTED DESIGN WORKFLOW Statechart Diagrams.
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.
State and Sequence Diagrams Modelling dynamic information So far we have seen: Use Case Diagrams – requirements capture, interface.
State Machines State diagrams SE-2030 Dr. Rob Hasker 1 Based on slides written by Dr. Mark L. Hornick Used with permission.
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
(C) 2009 J. M. Garrido1 Object Oriented Simulation with Java.
1 Object-Oriented Modeling Using UML (2) CS 3331 Fall 2009.
Business Informatics Group Institute of Software Technology and Interactive Systems Vienna University of Technology Favoritenstraße 9-11/188-3, 1040 Vienna,
Behavioral diagrams Lecture p4 T120B pavasario sem.
Object-Oriented Modeling Using UML CS 3331 Section 2.3 of Jia 2003.
1 A Student Guide to Object- Oriented Development Chapter 7 State Diagrams.
Software Engineering Design & Modeling Statechart Diagram.
1 Kyung Hee University Statecharts Spring Kyung Hee University Specifying Objects’ Behaviour  Interaction diagrams show message-passing behaviour.
Object Constraint Language
UML Discussion on State Machines Perfectly static system is intensely uninteresting Because nothing ever happens.
Karolina Muszyńska Based on: S. Wrycza, B. Marcinkowski, K. Wyrzykowski „Język UML 2.0 w modelowaniu SI”
Object Oriented Analysis & Design & UML (Unified Modeling Language)1 Part VI: Design Continuous Activity Diagams State Diagrams.
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.
Dynamic Models Sequence Diagrams Collaboration Diagrams Activity Diagrams.
States.
CS3773 Software Engineering Lecture 06 UML State Machines.
State Chart diagram Week objective Describe State chart Diagrams in Dynamic Modelling 2.
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.
Chapter 3: Introducing the UML
State Machines State diagrams SE-2030 Dr. Mark L. Hornick 1.
Modeling Object Lifecycles and State-Dependent Behavior ©SoftMoore ConsultingSlide 1.
State Machine Diagram Chapter 5 Introduction Pages
2/25/2016COSC , Lecture 191 Real-Time Systems, COSC , Lecture 19 Stefan Andrei.
State Modeling. Introduction A state model describes the sequences of operations that occur in response to external stimuli. As opposed to what the operations.
® IBM Software Group © 2009 IBM Corporation Module 11: Creating State Machine Diagrams Essentials of Modeling with IBM Rational Software Architect V7.5.
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.
Analysis Classes Unit 5.
State Machine Model.
State Machine Diagram.
State Machine Diagrams
Marlon Dumas Institute of Computer Science
State Machine Diagrams
Business System Development
CSC 422 Kutztown University Dr. Spiegel
UML Activity Diagrams & State Charts
States.
Object Oriented System Design
CS/CPE 426 Senior Projects
Advanced State Chart diagrams
Activity Diagrams.
Chapter 5 state Modeling
CS/CPE 426 Senior Projects
Marlon Dumas Institute of Computer Science
States.
CS 791Z State Machines & Advanced State Machines
UML State Diagrams.
Appendix 3 Object-Oriented Analysis and Design
Presentation transcript:

Statecharts Slide: 1

Objectives Learn the concepts for modeling object states Learn Statechart notation to depict object state models Do some modelling… Consider some issues… Slide: 2

Statecharts history and purpose Statecharts are a form of state transition diagram (STD) that allow for nesting, orthogonality (concurrency) and broadcasting, thus reducing the complexity of many STDs. They were invented by Israeli computer scientist David Harel. A statechart is used to describe the complex internal behavior of a class. It charts the possible lifecycles of objects from that class. (Similar to Entity Life Histories) Slide: 3

Statecharts usage A statechart is used to show the life cycle of the objects from complex classes. Simple classes do not need to have statechart. The state of an object is related to the values of its variables. A statechart can also be used for a system overview. A statechart can also be used for interface design. A statechart can be used to describe a protocol Slide: 4

State models - the basics State modelling uses a different set of concepts from Class diagrams, Interaction diagrams etc We need to understand the concepts and learn notation  Phases of an object’s lifecycle (States)  How an object changes its state (Events, Transitions)  Behaviour in each state (Actions, Activities) ... Also need to tie up with known OO concepts  operations, attributes… Slide: 5

State models - the basics click state transition event State - “A condition or situation during the life of an object during which it satisfies some condition, performs some activity, or waits for some event” Event - “A significant occurrence that has a location in time and space…a stimulus that can trigger a state transition” Transition - “A relationship between two states indicating that an object in the first state will perform certain actions and enter the second state when a certain event occurs and conditions are satisfied” OffOn Slide: 6

A simple Statechart (Door) Open Closed (unlocked) Closed (locked) close open lock unlock Slide: 7

Initial & Final States Baby Toddler Child Adult Teenager Initial State Final State Slide: 8

Thinking about Time For a class with a Statechart, each object is always in one of the defined states - never between states Therefore events and transitions are regarded as having zero or insignificant duration (ie there are no gaps between states) OffOn LAMP TRAFFIC LIGHT (UK) Off Time Slide: 9

Actions Armed Idle Ringing code entered / beep test button pressed Action - “An executable atomic computation that results in a change of state of the system or the return of a value” Deemed to have insignificant duration & be non-interruptible Actions may appear on transitions, or inside states (internal transition). Burglar Alarm System intruder detected / start alarm Test Mode intruder detected / beep code entered / silence alarm test button pressed Slide: 10

Activities Armed Idle Ringing code entered / beep Activity - “ongoing non-atomic execution within a state machine” Has duration & is interruptible Can only be placed inside states (not on transitions). May be a sequence of actions or may name another state machine Indicated by keyword do/ intruder detected Counting do / countdown / start alarm Slide: 11

Activity states Activity State Ordinary State States with ongoing activities are known as Activity States UML provides an alternative notation to visually distinguish them Activity States also used in Activity Diagrams Slide: 12

Automatic transitions Idle Ringing code entered / beep Aka Triggerless transition or Completion transition “Triggered implicitly when source state completes its activity”  so this activity cannot be an endless loop Counting Automatic transition - requires no event Activity state Slide: 13

Useful Keywords entry/ - pseudo event inside a state, associated action(s) to be performed whenever the object enters (or re-enters) the state. exit/ - pseudo event inside a state, associated action(s) to be performed whenever the object leaves the state. do/ - inside a state, identifies an activity after/ - indicates a relative time. Eg after 2 seconds; after 1 ms since exiting idle. (Default start time is entry to current state) when/ - indicates a condition becoming true (including absolute times) Eg when 11.30; when temp < 0. /defer - pseudo action inside a state, associated event(s) not handled in current state, but not totally discarded either - queued for handling in a subsequent state. Slide: 14

Processing Sequence When event E occurs (and object is in state A):  Activity A is terminated.  Exit action K is performed.  Action X on the transition is performed.  Entry action P is performed.  Activity B is started. State A do / activity A entry / action J exit / action K State B do / activity B entry / action P exit / action Q event E / action X Slide: 15

Self Transitions Event E (self transition) =>  Stop activity A  Perform actions K, X, J  Start activity A Event F (internal transition) =>  Perform action Z State A do / activity A entry / action J exit / action K event F / action Z event E / action X Slide: 16

Statecharts - advanced Slide: 17

Guard conditions Spaces Available Full booking [delegates = capacity] booking [delegates < capacity] / add delagate A training course Qualifies whether to respond to event Boolean condition Evaluated when event is detected Actions/transition only occur if condition is true Allows same event to be associated with multiple responses Slide: 18

Sub-states Super Sub1Sub2 A state can be decomposed into sub-states One of the sub-states can be the default initial state for that super- state Transitions can go to & from super-state or sub-states  entry/exit actions performed in defined sequence Slide: 19

Concurrent sub-states On Desk On Floor Light Off Light On Overhead Projector Slide: 20

State explosions Bold off Italics off Underline off Bold off Italics on Underline off Bold off Italics off Underline on Bold on Italics off Underline off Bold on Italics on Underline off Bold on Italics off Underline on Bold on Italics on Underline on Bold off Italics on Underline on A text item – most transitions not shown! BI U BI U U U B B I I Slide: 21

Orthogonal states Bold on Underline on Bold off Italics on Italics off Underline off BBIIU U Slide: 22

History states B2 B1 C H interrupt resume indicates a deep history H* A B Slide: 23

Junction States SourceTarget exit / p entry / q Junction states f / a;b;c / b e /a / c e / a; p; b; q; c f / p; a; b; c; q Outcomes - Slide: 24

Join and Fork A1A2 B1B2 forkjoin Slide: 25

Implementing States Statechart concepts must be mapped to OO concepts Events, States, Actions, Activities, Transitions, Guards A B2 B1 Class operations attributes associations Slide: 26

‘State’ Design Pattern (1) INTENT – Allow an object to alter its behaviour when its internal state changes. The object will appear to change its class. TCPEstablished open() close() acknowledge() TCPConnection open() close() acknowledge() TCPListening open() close() acknowledge() TCPClosed open() close() acknowledge() X Heuristic – normally an object should not actually change its class From Design Patterns Gamma, Helm, Johnson, Vlissides Slide: 27

‘State’ Design Pattern (2) TCPEstablished open() close() acknowledge() state.Open() TCPConnection open() close() acknowledge() TCPState open() close() acknowledge() TCPListening open() close() acknowledge() TCPClosed open() close() acknowledge() From Design Patterns Gamma, Helm, Johnson, Vlissides Slide: 28

Statechart example Initial StateFinal State Transition State Nested State Event (event parameter) Action Slide: 29

Object Constraint Language Slide: 30

What is a constraint Account Transaction {self.transaction -> forAll(t:Transaction | t.value > 100)} 0..*1 An Account can only hold transactions worth more than £100 Slide: 31

Design by Contract put (element: T, key: STRING) is -- insert element with given key require count < capacity do.. insertion algorithm... ensure count <= capacity; item (key) = element; count = old count + 1 end --put ObligationsBenefits Client Contractor Call put only on a non-full table Get modified table in which x is associated with key Insert x so that it may be retrieved through key No need to deal with the case in which the table is full before insertion Slide: 32

OCL requirements The OCL must enable us to express extra, necessary, information on object models. The OCL must be a precise and unambiguous language that can be easily read by developers and customers. The OCL must be a declarative language, its expressions can have no side-effects. OCL must be a typed language so that OCL expressions can be type checked for correctness. Slide: 33

OC Language is... OCL is a typed language The OCL is a language of expressions. An OCL expression is valid if it is written according to the rules (formal grammar) of OCL. A constraint is a valid OCL expression of type Boolean. A constraint is a restriction on one or more values of (part of) an object-oriented model or system. Slide: 34

Boolean expressions Customer name: String title: String age: Integer isMale: Boolean title = if isMale then ‘Mr.’ else ‘Ms.’ endif age >= 18 and age < 66 name.size < 100 Slide: 35

Context for a constraint Wheel Vehicle self.wheelCount = Slide: 36

Multiplicity constraints VocabularyVocabElementHint *11 VocabElement self.hint -> size >= 0 and self.hint -> size <= 5 VocabElement self.vocabulary -> size = 1 Hint self.vocabElement -> size = 1 Equivalent constraints expressed on the classes Slide: 37

Subset constraint FlightPerson pilot flightAttendant crew Flight self.crew -> includes( self.pilot ) Flight self.crew -> includesAll(self.flightAttendants) 0..* 1..* Slide: 38

OCL collections Collection SetBagSequence minus symmetricDifference asSequence asBag first last at(int) append prepend asBag asSet asSequence asSet Slide: 39

OCL Summary Constraints are required in the UML because the notations can never be sufficiently expressive to capture all we know. Constraints are one way to practice design by contract. The OCL is a formal notation for precisely specifying constraints in object models. Slide: 40

Module Summary Statecharts in UML are related to classes and they describe the possible lifetimes of all the possible objects from that class. Statecharts are an advance on earlier state modeling notations because they allow nesting and concurrency. Statecharts are only drawn for classes with significant complexity. Statecharts can be used for more than object lifecycle modeling. Slide: 41

Questions or Comments? Slide: 42