ObjectOriented Analysis and Design Chapter 5 State Modelling
Object-Oriented Analysis and Design Chapter 5: State Modelling © RKU 2014 Prepared By Ashwin Raiyani
Object-Oriented Analysis and Design Chapter 5: State Modelling Topic Covered • State Modeling • Event – Types of Event • • State Transition and Condition Sample and One-Shot State Diagram Behavior © RKU 2014 Prepared By Ashwin Raiyani
Object-Oriented Analysis and Design Chapter 5: State Modelling State model • It describes the sequences of operations that occur in response to external stimuli • State model consists of multiple state diagrams. • Each state diagram shows the state and event sequences permitted in a system. • Event represent external stimuli and states represent values of object. © RKU 2014 Prepared By Ashwin Raiyani
Object-Oriented Analysis and Design Chapter 5: State Modelling Event • An event is occurrence at a point in time. • An event is instantaneously with regards to time scale. • Time at which event occurs is an implicit attribute of the event. • Event may logically precede or follow another or the two events may be unrelated. • Two events that are causally unrelated are said to be concurrent; they have no effect on each other. © RKU 2014 Prepared By Ashwin Raiyani
Object-Oriented Analysis and Design Chapter 5: State Modelling © RKU 2014 Prepared By Ashwin Raiyani
Object-Oriented Analysis and Design Chapter 5: State Modelling Contd. • In modeling, do not try to establish an ordering between concurrent events because they can occur in any order. • Events also include error conditions as well as normal occurrences. – For ex. System hang, transaction aborted or timeout are error events. • Only interpretation makes it an “error”. • The precise meaning is apparent from the context. © RKU 2014 Prepared By Ashwin Raiyani
Object-Oriented Analysis and Design Chapter 5: State Modelling Kinds of Events Event Signal Event © RKU 2014 Change Event Time Event Prepared By Ashwin Raiyani
Object-Oriented Analysis and Design Chapter 5: State Modelling Signal Event • A signal is an explicit one-way transmission of information from one object to another. • An object sending a signal to another object may expect a reply, but the reply is a separate signal under the control of the second object. • A signal event is the event of sending or receiving a signal. • Here receiver object has only causes effect. • Difference between – Signal – a message between object – Signal event – an occurrence in time. © RKU 2014 Prepared By Ashwin Raiyani
Object-Oriented Analysis and Design Chapter 5: State Modelling Contd. • Signal classes is group of signals where each signal transmission has unique occurrence. • Signal classes have attributes indicating the value they convey. – For ex. UA flight 123 departs from Chicago on January 10, 1991. • Here, Flight. Departure signal class has attribute airline, flight. Number, city and date. UML notation: – Keyword signal in guillemets (<<>>) above the signal class name in the top section of a box. – Second section lists the signal attributes. © RKU 2014 Prepared By Ashwin Raiyani
Object-Oriented Analysis and Design Chapter 5: State Modelling UML notation © RKU 2014 Prepared By Ashwin Raiyani
Object-Oriented Analysis and Design Chapter 5: State Modelling Change Event • An event that is caused by the satisfaction of a boolean expression. • Intent of a change event is that expression is continually tested – whenever expression change from false to true, the event happens. UML notation: • keyword when followed by a parenthesized boolean expression. n when ( no_of_book_allocate < no_of_book_issued) © RKU 2014 Prepared By Ashwin Raiyani
Object-Oriented Analysis and Design Chapter 5: State Modelling Time Event • Event caused by the occurrence of an absolute time or the elapse of a time interval. UML notation: • For absolute time – keyword when follwed by parenthesized expression involving time. • For time interval – keyword after followed by parenthesized expression involving time duration. n when ( date= January 26, 2001) n after (10 seconds) © RKU 2014 Prepared By Ashwin Raiyani
Object-Oriented Analysis and Design Chapter 5: State Modelling State • A state is an abstraction of the values and links of an object. • Sets of values and links are grouped together into a states. • States often correspond to verbs with suffix of “ing” (calling, dialing) or the duration of some condition (called, dialed). • UML notation – Rounded box containing an optional state name. – State name in boldface, center the name and capitalize the first letter. © RKU 2014 Prepared By Ashwin Raiyani
Object-Oriented Analysis and Design Chapter 5: State Modelling Waiting Dialing • In defining states, we took those only attributes that affect the behavior of the object. • Obviously, each attribute has some effect on behavior or it would be meaningless. Note: • Objects in class have a finite number of possible states. • Each objects can only be in one state at a time. • Objects may show off through one or more states during their lifetime. © RKU 2014 Prepared By Ashwin Raiyani
Object-Oriented Analysis and Design Chapter 5: State Modelling Contd. • A state specifies the response of an object to input events. • Response may include the invocation of behavior or a change of state. For example: • States are Idle, Dial Tone and Dialing. • If digits is dialed in state Dial. Tone then state change into Dialing. • If receiver put down in state Dial. Tone then state change into Idle © RKU 2014 Prepared By Ashwin Raiyani
Object-Oriented Analysis and Design Chapter 5: State Modelling • Certain symmetry between events and states ▫ Events represent points in time ▫ State represent interval of time. • A state corresponds to the interval between two events received by an object. ▫ For ex. After receiver is lifted and before first digit dialed, phone line is in state Dial. Tone • The state of an object depends on past event. © RKU 2014 Prepared By Ashwin Raiyani
Object-Oriented Analysis and Design Chapter 5: State Modelling State : Alarm. Ringing Description: alarm on watch is ringing to indicate target time Event sequence that produces the state: set. Alarm(target. Time) any sequence not including clear. Alarm when (current. Time = target. Time) Condition that characterizes the state: alarm = on, alarm set to target. Time, target. Time =< current. Time=< target. Time + 20 seconds, and no button has been pushed since target. Time Event accepted in the state: Event Response next state When (current. Time = reset. Alarm normal target. Time + 20 ) button. Pushed (any reset. Alarm normal button) Various characterizations of a state © RKU 2014 Prepared By Ashwin Raiyani
Object-Oriented Analysis and Design Chapter 5: State Modelling Transitions and conditions • A transition is an instantaneous change from one state to another. • For ex. Called phone is answered, the phone line transitions from the Ringing state to the Connected state. • Transition mean change from source state to target state. • Source and target of a transition usually are different state, but may be the same (i. e. Self transition). • A transition fires when its event occurs. © RKU 2014 Prepared By Ashwin Raiyani
Object-Oriented Analysis and Design Chapter 5: State Modelling Guard Conditions • It is a boolean expression that must be true in order for a transition to occur. • A guarded transition fires when its event occurs, but only if guard condition is true. For ex. When you go out in the morning (event), if temperature is below freezing (condition), the put on your gloves (next state) • Guard condition checked only once (event occur time) and transition fires if condition is true. © RKU 2014 Prepared By Ashwin Raiyani
Object-Oriented Analysis and Design Chapter 5: State Modelling Guard Condition UML notation: • Transition is a line from origin to target state. • Arrowhead points to the target state. • Line may consist of several line segments. • Event may label the transition and be followed by an optional guard condition in square brackets. • Event name in italic and condition in normal font. © RKU 2014 Prepared By Ashwin Raiyani
Object-Oriented Analysis and Design Chapter 5: State Modelling State Diagrams • A state diagram is a graph – Nodes are states – Directed arcs are transitions between states. • A state diagram specifies the state sequences caused by event sequences. • State name must be unique within the scope of a state diagram. • The state model consists of multiple state diagrams. • One state diagram for each class with important temporal behavior. • State must match on their interfaces (i. e. Event and guard conditions) © RKU 2014 Prepared By Ashwin Raiyani
Object-Oriented Analysis and Design Chapter 5: State Modelling Phone. Line © RKU 2014 Sample state diagram Prepared By Ashwin Raiyani
Object-Oriented Analysis and Design Chapter 5: State Modelling UML notation • State diagram is a rectangle with its name in small pentagonal tag in the upper left corner. • Constituent states and transitions lie within the rectangle. Notes: • If more than one transition leaves a state, then the first event to occurs causes the corresponding transition to fire. • If an event occurs and no transition it, then event is ignored. • If more than one transition matches an event, only one transition will fire but the choice is nondeterministic © RKU 2014 Prepared By Ashwin Raiyani
Object-Oriented Analysis and Design Chapter 5: State Modelling One-shot State Diagrams • State diagram can represent continuous loops or one-shot life cycles. • One-shot state diagram represent objects with finite lives and have initial and final states. • The initial state is entered on creation of an object; entry of the final state implies destruction of the object. UML notation • Default Initial state indicate by solid circle. • Default final state indicate by bull’s eye. © RKU 2014 Prepared By Ashwin Raiyani
Object-Oriented Analysis and Design Chapter 5: State Modelling Ex. Default initial and final state Chess Final state Initial state © RKU 2014 Prepared By Ashwin Raiyani
Object-Oriented Analysis and Design Chapter 5: State Modelling Ex. Entry and exit points Chess Black wins X Start Draw X White wins X © RKU 2014 Prepared By Ashwin Raiyani
Object-Oriented Analysis and Design Chapter 5: State Modelling • Alternate solution , you can indicate initial an final state via entry and exit points. UML notation • Entry points indicate by hollow circle • Exit points indicate by circles enclosing an “X” appear on the state diagram’s perimeter and may be named. © RKU 2014 Prepared By Ashwin Raiyani
Object-Oriented Analysis and Design Chapter 5: State Modelling Summary of basic state diagram notation State Diagram name State 1 do / activity event /effect Event(attribs)[condition]/effect State 2 ……. • State: Drawn as a rounded box containing an optional name. – Initial state solid circle – Final state a bull’s eye or encircled “X” © RKU 2014 Prepared By Ashwin Raiyani
Object-Oriented Analysis and Design Chapter 5: State Modelling • Transition: – Line from origin to the target state – An arrowhead point to target state – Line may consists of several line segments. • Event: – Signal event is shown as a label on a transition and may followed by parenthesized attributes. – Change event – keyword when followed by parenthesized boolean expression involving time. – Time event – keyword after followed by a parenthesized expression that evaluates to time duration. © RKU 2014 Prepared By Ashwin Raiyani
Object-Oriented Analysis and Design Chapter 5: State Modelling • State diagram: – Enclosed in a rectangular frame with the diagram name in a small pentagonal tag in the upper left corner. • Guard condition: – Optionally listed in square brackets after an event. • Effects: – Can be attached to a transition or state and are listed after a slash “/”. State name in boldface with first letter capitalize. Event name in italic with first letter in lower case Guard condition and effects are in normal font with first letter in lower case. © RKU 2014 Prepared By Ashwin Raiyani
Object-Oriented Analysis and Design Chapter 5: State Modelling State Diagram behavior • • • Activity effects Do-activities Entry and Exit activities Completion Transition Sending Signals. © RKU 2014 Prepared By Ashwin Raiyani
Object-Oriented Analysis and Design Chapter 5: State Modelling Activity Effects • An Effect is a references to a behavior that is executed in response to an event. – For ex, In state Dial. Tone, when pressed number or digits (event). Effect is dialing start. • An Activity is the actual behavior that can be invoked by any number of effects. – For ex. disconnect. Phone. Line might be an activity that is executed in response to Receiver. Down event. • An activity may be performed upon – A Transition – The entry to or exit from a state. – Some other event within a state. © RKU 2014 Prepared By Ashwin Raiyani
Object-Oriented Analysis and Design Chapter 5: State Modelling UML notation: • Activity is a slash (“/”) and the name (0 r description) of the activity, following the event that causes it. • Keyword do is reserved for indicating an ongoing activity and may not be used as an event as an name. • Ex. Pop up menu for workstation. © RKU 2014 Prepared By Ashwin Raiyani
Object-Oriented Analysis and Design Chapter 5: State Modelling Do-Activities • A do-activity is an activity that continues for an extended time. • In other word, object does some work that will continue until it is interrupted by an event. • A do-activity can only occur within a state and cannot be attached to transition. • For example, In Dial. Tone state, sound should come from phone. Dial. Tone do / sound. Dial. Tone © RKU 2014 Prepared By Ashwin Raiyani
Object-Oriented Analysis and Design Chapter 5: State Modelling • Do-activities include continuous operation as well as sequential operations that terminate by themselves after an interval of time. UML notation: • “Do /” denotes a do-activity Notes • A do-activity may be interrupted by an event that is received during its execution. © RKU 2014 Prepared By Ashwin Raiyani
Object-Oriented Analysis and Design Chapter 5: State Modelling Entry and Exit activities • You can bind activities to entry or to exit from a state. • Usually, you perform some setup action whenever you enter a state and exit from a state. • Fig. shows control of garage door opener. It shows activities on transition. © RKU 2014 Prepared By Ashwin Raiyani
Object-Oriented Analysis and Design Chapter 5: State Modelling Activities on entry to states © RKU 2014 Prepared By Ashwin Raiyani
Object-Oriented Analysis and Design Chapter 5: State Modelling • An entry activity is shown inside the state box following keyword entry and a “/” character. • Whenever the state is entered, entry activity is performed. • Entry equivalent to attaching the activity to every incoming transition. • If an incoming transition already has an activity, it is performed first. • Similarly, for exit activity, state box following keyword exit and a “/” character. • For any outgoing transition from state, exit activity is performed first. © RKU 2014 Prepared By Ashwin Raiyani
Object-Oriented Analysis and Design Chapter 5: State Modelling • If state has multiple activities, they performed in the following order: – Activities on the incoming transition – Entry activities – Do-activities – Exit activities – Activities on the outgoing transitions • May be Do-activities can be interrupted by event but exit activity still performed. © RKU 2014 Prepared By Ashwin Raiyani
Object-Oriented Analysis and Design Chapter 5: State Modelling • Any event can occur within a state and cause an activity to be performed. • In that case, Entry and Exit activities are only performed. • A self-transition causes entry and exit activities to be executed. Closed shutdown/ motor off © RKU 2014 Prepared By Ashwin Raiyani
Object-Oriented Analysis and Design Chapter 5: State Modelling Completion Transition • Solely purpose of a state is to perform a sequential activity. • When the activity is completed, a transition to another state fires. • An arrow without an event name indicates an automatic transition that fires when source state is completed. • Such unlabeled transitions called completion transitions. • If state has one or more completion transitions, but none of the guard conditions are satisfied, then the state remain active and may become “stuck”. © RKU 2014 Prepared By Ashwin Raiyani
Object-Oriented Analysis and Design Chapter 5: State Modelling • If a state has completion transitions, guard condition should cover every possible outcome. • You can use special condition else to apply if all other conditions are false. © RKU 2014 Prepared By Ashwin Raiyani
Object-Oriented Analysis and Design Chapter 5: State Modelling Sending Signal • Object can perform the activity of sending to a signal to another object. • Activity “send target. S(attributes)” sends signal S with given attributes to the target object or objects. • For ex. Phone line sends a connect(Phone Number) signal to the switcher when completed number dialed • If the target is a set of objects, each of them received separate copy of the signal concurrently and each of them independently processes the signal. © RKU 2014 Prepared By Ashwin Raiyani
Object-Oriented Analysis and Design Chapter 5: State Modelling © RKU 2014 Prepared By Ashwin Raiyani
- Slides: 44