Modeling Object Lifecycles and State-Dependent Behavior ©SoftMoore ConsultingSlide 1.

Slides:



Advertisements
Similar presentations
NCKU EE RTES LAB.1 Unified Modeling Language - Events and State Machines.
Advertisements

State Charts Mehran Najafi. Reactive Systems A reactive, event-driven, object is one whose behavior is best characterized by its response to events dispatched.
Concepts & Notations. Acknowledgements  The material in this tutorial is based in part on: Concurrency: State Models & Java Programming, by Jeff Magee.
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.
Dynamic Modeling. Dynamic Modeling with UML Interaction diagram –Dynamic behavior of a set of objects arranged in time sequence –Interaction between objects.
© 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.
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.
Using UML, Patterns, and Java Object-Oriented Software Engineering Chapter 5, Analysis: Dynamic Modeling.
Ch5: Software Specification. 1 Dynamic modeling using UML  Static models:  Dynamic models:
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.
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.
Lecture 4 Finite State Machine CS6133 Software Specification and Verification.
Chapter 10 State Machine Diagrams
מידול התנהגותי 1. Today’s Session Sequence Diagrams State Machines 2.
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,
NJIT Modeling Behavior in State Chart Diagrams Chapter 29 Rafael Mello.
Introduction to the Unified Modeling Language “The act of drawing a diagram does not constitute analysis or design. … Still, having a well-defined and.
Fall 2010 CS4310 Requirements Engineering UML: Dynamic Modeling Dr. Guoqiang Hu Department of Computer Science UTEP 1.
1 Software Engineering Dr. K. T. Tsang Lecture 8 State modeling
Guide to State Transition Diagram. 2 Contents  What is state transition diagram?  When is state transition diagram used?  What are state transition.
Object-Oriented Modeling Using UML CS 3331 Section 2.3 of Jia 2003.
Sequence & Statechart Diagrams Month Day, Year. Agenda Training Plan Overview Actors and Use Case Diagrams Sequence Diagrams Diagram Elements Evolution.
1 Modeling interactions and behavior Lecturer Dr. Mai Fadel.
UML -Part 3. Dynamic Diagram Types Interaction Diagrams - Set of objects or roles and the messages that can be passed among them. – Sequence Diagrams.
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
Software Engineering Design & Modeling Statechart Diagram.
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.
Chapter 11 Activity Diagrams. 2 “Activity diagrams are a technique to describe procedural logic, business processes, and work flows” - M. Fowler An activity.
State Modeling. Introduction A state model describes the sequences of operations that occur in response to external stimuli. As opposed to what the operations.
Object Oriented Analysis & Design & UML (Unified Modeling Language)1 Part VI: Design Continuous Activity Diagams State Diagrams.
State Modeling. Events An event is an occurrence at a point in time, such as user depresses left button or.
© 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 1 UML State Diagrams.
States.
CS3773 Software Engineering Lecture 06 UML State Machines.
SOFTWARE DESIGN AND ARCHITECTURE LECTURE 26. Review UML behavioral Diagrams – Sequence diagram.
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.
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.
1 7 Systems Analysis and Design in a Changing World, 2 nd Edition, Satzinger, Jackson, & Burd Chapter 7 The Object-Oriented Approach to Requirements.
Module 2 OOMD.
Test Generation from UML Specifications Michael A. Gray American University Washington, DC.
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.
UML Review: State Machines. Sept. 17, 2003Lecture 5: CS660 Fall Overview States Transitions Activities Modeling object lifeline Creating well-structured.
State Machine Model.
State Machine Diagrams
Activity and State Transition Diagram
State Machine Diagrams
CS251 – Software Engineering Lectures 11 State Diagrams
CSC 422 Kutztown University Dr. Spiegel
UML Activity Diagrams & State Charts
UML State machine diagram
States.
Object Oriented System Design
Activity Diagrams.
Chapter 5 state Modeling
States.
UML State Diagrams.
Presentation transcript:

Modeling Object Lifecycles and State-Dependent Behavior ©SoftMoore ConsultingSlide 1

State A state is a condition or situation during the life of an object during which it satisfies some condition, performs some activity, or waits for some event. Conceptually, a state is an abstraction of the attribute values and links of an object. Sets of values are grouped together into a state according to properties that affect gross behavior of the object. An object is said to “be in” a particular state. Example: A traffic light may be in one of three states: red, yellow, or green. ©SoftMoore ConsultingSlide 2

State (continued) At any instant in time, an object is usually thought of as being in exactly one state (but concurrent substates are sometimes allowed). An object usually remains in a state for a finite amount of time. Naming states –simple adjectives such as “Off” or “Active” –participial verb phrases such as “Processing” or “Closed” ©SoftMoore ConsultingSlide 3

State-Dependent Behavior State-dependent behavior: The object’s response to a message depends not only on the message and its parameters but also on the state of the object at the time the message is received. Most objects exhibit some state-dependent behavior. Some exhibit complex state-dependent behavior. Example: An elevator door receives a message asking it to open. The door’s response will depend on whether or not its associated elevator is moving. Example: An order receives a message to ship. Its response will depend on whether or not it is in a “hold” state pending a credit check of the customer. ©SoftMoore ConsultingSlide 4

State Machines A state machine specifies the sequences of states and actions that an object goes through during its lifetime in response to discrete events. A state machine models the dynamic behavior of an individual object –object lifecycle –state-dependent behavior ©SoftMoore ConsultingSlide 5 Interactions describe dynamics between several objects. State machines describe dynamics within a single object.

Statechart Diagrams A statechart diagram models a state machine –relates states, events, and transitions –emphasizes flow of control from state to state –notation and semantics based on work by David Harel A statechart diagram is a directed graph –nodes represent states –directed arcs represent transitions from one state to another –arcs are labeled by the event that causes the transition ©SoftMoore ConsultingSlide 6 State1State2 event

Notation for States A state is usually rendered as a rectangle with rounded corners May be divided into two optional compartments –name compartment (states may be anonymous) –internal transitions compartment ©SoftMoore ConsultingSlide 7 State Name entry / entry effect do / do-activity event / internal transition exit / exit effect

Initial and Final States Initial state –default starting place for the state machine or substate –initial pseudostate rendered as a small solid circle Final state –indicates completion of the state machine (or the enclosing state when used with nested substates) –rendered as solid circle inside an unfilled circle (bull’s eye) ©SoftMoore ConsultingSlide 8 State

State Versus Attribute Values Sometimes we establish a different state for each possible set of attribute values for an object. This is especially true for simple objects. Example: A lamp can have one of two states, off or on. The state of an object is often associated with some condition that must be satisfied by one or more of its attribute values. Example: Water could have an attribute called temperature that takes on many values, but we can think of water as being in one of three states – ice, liquid, or steam – based on specific ranges of its temperature. ©SoftMoore ConsultingSlide 9

States and Reader-Writer Operations If an object can be in a particular state, there should usually be one or more update operations (sometimes called “writers”) in the class that cause the object to be placed in that state. If an object is considered to be in a particular state, there should usually be a query operation (sometimes called a “reader”) in the class that can query the object to determine if it is in that state. ©SoftMoore ConsultingSlide 10

Transition An object's response to an event or stimulus is described in terms of an action performed by the object and/or a change in the state of the object. A change in state caused by an event is called a transition. When the object changes from the source state to the target state, the transition is said to “fire.” A transition is rendered as a solid directed line from the source state to the target state. ©SoftMoore ConsultingSlide 11

Events An event is the specification of a significant occurrence that has a location in time and space. An event occurs at a particular point in time. In the context of state machines, an event is an occurrence of a stimulus that can trigger a state transition. Conceptually, we view the occurrence of an event as being relatively fast compared to the granularity of the time scale of the overall model; event occurrence is essentially “instantaneous.” ©SoftMoore ConsultingSlide 12

Characteristics of Events Events may be External (between an actor and the system) or internal (between objects inside the system) Synchronous or asynchronous (analogy with phone call versus ) Intraprocess or interprocess ©SoftMoore ConsultingSlide 13

Example: Automobile Cruise Control System ©SoftMoore ConsultingSlide 14 OffOn CoastingCruising on button off button brake set speed resume coast button depressed coast button released brake

Kinds of Events Call Event –Synchronous (in general) –Invocation of an operation Signal –Asynchronous –e.g., exceptions Time Event –Asynchronous –Represents the passage of time Change Event –Asynchronous –Represents a condition becoming true ©SoftMoore ConsultingSlide 15 schedule (request) obstructionDetected after (2 seconds) when (altitude < 1000 feet)

Guard Conditions In addition to the event trigger, a transition may also have a guard condition that controls when the transition fires. A guard condition is rendered as a boolean expression enclosed in square brackets following the event. A guarded transition fires whenever the event trigger occurs and the condition evaluates to true. ©SoftMoore ConsultingSlide 16 item selected [balance  item cost]

Effects An effect is an executable behavior (action) –atomic (uninterruptable) computation. Examples –operation call –creation or destruction of an object –sending a signal to an object (uses keyword send) Effects are associated with events (performed in response to the event occurrence). A transition may include an effect that is performed when the transition fires. ©SoftMoore ConsultingSlide 17 eventName [guardCondition] / effect

Example: Bounded Queue ©SoftMoore ConsultingSlide 18 EmptyNonEmptyFull append append [size < capacity - 1] append [size = capacity - 1] clear remove remove [size > 1] remove [size = 1]

Modeling States: The Internal Transitions Compartment Entry effect: performed on entry to the state Exit effect: performed on exit from the state Do-Activity: ongoing operation performed while the object is in the state Internal transitions: performed in response to events (object does not change state) Deferred Events: (specified as “eventName / defer”) event is queued and response is postponed until the object enters a state for which it is not deferred ©SoftMoore ConsultingSlide 19

Triggerless Transitions A transition whose source state contains an activity is not required to have an event trigger. Such a transition is called a triggerless transition. (also called a completion transition or an automatic transition) A triggerless transition is considered to fire when the activity associated with the source state is completed. ©SoftMoore ConsultingSlide 20 State1 do / do-activity State2

Example: Vending Machine ©SoftMoore ConsultingSlide 21 Idle entry / set balance to 0 Collecting entry / update balance Dispensing do / dispense selected item and change money in cancel / refund balance money in item selected [balance  item cost]

Composite States A simple state is a state that has no substructure. A state that has substates is called a composite state. Substates may be nested to any level. A composite state may contain either sequential or concurrent substates. Substates inherit the transitions of the enclosing composite state. Any transition or action that applies to the composite state applies to all of its substates unless overridden by an equivalent transition on the substate. ©SoftMoore ConsultingSlide 22

Example: Automobile Cruise Control System – Version 2 ©SoftMoore ConsultingSlide 23 Off off button On set speed resume brake on button Cruising Coasting Manual Control coast button depressed coast button released

Modeling with State Machines A state machine is commonly associated with a class to model the lifetime and state-dependent behavior of its objects. –at most one state machine per class –may have composite states spanning more that one diagram –all objects of the class exhibit the dynamic behavior specified by the state machine Construct statechart diagrams only for classes whose objects exhibit meaningful dynamic behavior (reactive objects). Not every class requires a statechart diagram. ©SoftMoore ConsultingSlide 24