Download presentation
Presentation is loading. Please wait.
Published byArron Harrell Modified over 9 years ago
1
1 A Student Guide to Object- Oriented Development Chapter 7 State Diagrams
2
2 State diagram In sequence diagrams you are looking at all the classes affected by one use case In state diagrams you are looking at one class across all use cases and how it is effected by the events in the system
3
3 State diagrams are increasingly widely used to model the ways that a system can respond to external events All objects of the class (the individual customers or products) have the same range of ways in which they can behave, but the actual way an individual object does behave during the running of the system depends on the sequence of events that it experiences. State diagrams look at how a class is affected by the different use cases in the system and how the objects of the class behave in response to events that affect them. They model the behaviour of one object across several use cases. State diagram
4
4 State Diagram A state diagram only ever describes the behaviour of a single class illustrating how its objects behave during their lifetimes and how they react to all uses cases in which they are involved. State diagrams also model the order that events affect an object in e.g. in the Wheels system the bike must be assigned a number before it can be hired In most systems only a few of the classes are complicated enough to merit a state diagram. These are classes where the response of an object of the class to a particular event varies depending on the state the object is in at the time State diagrams are also referred to as state charts and state transition diagrams
5
5 States and Events State - The state of the object here refers to the situation it is in while satisfying some condition (such as a bank account having some money) or waiting for an event (such as someone trying to withdraw or deposit money). Event - An event is something that happens which has significance for the system and affects an object of at least one of the system’s classes. We can tell if an object is in a particular state by looking at the values of some of its attributes and its links to other objects.
6
6 The state of an object We can tell if an object is in a particular state by looking at the values of its attributes For example, if a Bank Account object is in credit the value of the balance attribute will be a positive amount or zero, but if it is overdrawn the value of balance will be negative. In the Wheels case study, we can tell if a bike is hired out because there will be a link from the Bike object to an active Hire object.
7
7 start state stop state transition from one state to another self-transition (no change of state) event [guard] / action transition label (each of the three parts is optional) state
8
8 state diagram for a bank account class State diagram for a bank account class Start state stop state Event fires a transition Self transition Guard
9
In the "In credit" state 9
10
UML and C++ A Practical Guide To Object-Oriented Development State Model State Model describes the sequence of states that an object goes through during its lifetime in response to events. Includes the objects responses to events –Actions Single act performed by the object –Activities Continuous set of actions performed by an object
11
UML and C++ A Practical Guide To Object-Oriented DevelopmentState This represents a stage in the lifecycle of an object. Technically the period of time during which an object is waiting for an event to occur. The internal state of an object is the combination of the data values of the attributes of object.
12
UML and C++ A Practical Guide To Object-Oriented DevelopmentEvent An event is a condition that can be detected by an object. From an programmatic perspective –An event is a one way asynchronous transmission of information from one object to another. –The information may have parameters with names and types as part of the message sent
13
UML and C++ A Practical Guide To Object-Oriented DevelopmentTransition A transition is a response by an object to an event received by it. –The response can be a change to a new object state a change to the same object state the performance of some action The ability of the object to respond to a given event is described by guard conditions.
14
UML and C++ A Practical Guide To Object-Oriented DevelopmentAction An action is an activity or operation that is done inside a state or on a transition between states An action is –atomic –instantaneous An action can occur –during a transition –on entry to a state, –during the entire period an object is in a state, –on exit from a state, –on arrival of an event that does not cause a state transition
15
UML and C++ A Practical Guide To Object-Oriented DevelopmentActivity An activity is an operation or set of operations that executes during the entire time an object is in a state. An activity is not atomic. An activity can be interrupted by an event while it is executing
16
Events for Bike Object 16
17
Completed state diagram for Bike Object 17
18
18 State diagrams – key words ‘after’ – used to show an event taking place after a specified time period e.g. after [6 months] / delete ‘when’ – event takes place when a condition is satisfied e.g. when [all items in stock] / fill order
19
19 State diagrams – entry and exit events offHook entry / start dialling tone exit / stop dialling tone do / emit dialling tone Keyword ‘do’ – behaviour that lasts for the duration of a state is called an activity, it is modelled using the keyword ‘do’
20
UML and C++ A Practical Guide To Object-Oriented Development Nested State Diagram
21
UML and C++ A Practical Guide To Object-Oriented Development Nested Concurrent Substates
22
UML and C++ A Practical Guide To Object-Oriented Development Nested Concurrent Substates
23
UML and C++ A Practical Guide To Object-Oriented Development Mealy model for Microwave Oven
24
UML and C++ A Practical Guide To Object-Oriented Development Moore model
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.