Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Ooad content of unit vii

54 views

Published on

Ooad content of unit vii

Published in: Engineering
  • Be the first to comment

  • Be the first to like this

Ooad content of unit vii

  1. 1. Subject: Object Oriented Analysis and Design B.Tech III Year II-Semester Computer Science &Engineering
  2. 2. Table of Contents Unit-VII: State machines • State machines and the UP • State machine diagrams • States • Transitions • Events • Advances state machines • Composite states • Submachine states • Submachine Communication • History
  3. 3. Learning Objectives At the end of this unit the student will be in a position to: • Create State machine diagrams • Understand States, Transitions, and Events • Understand the difference between Activity diagram and State machine diagrams • Understand the Composite states • Specify Submachine Communication • Understand the use of History States
  4. 4. State machines • Using an interaction diagram, you can model the behavior of a society of objects that work together. • We use Activity and state machine diagrams to model the dynamic aspects of a System. • An Activity diagram is essentially a flow chart, showing flow of control from activity to activity. • Using a state machine ,you can model the behavior of an individual object. • A State machine is a behavior that specifies the sequences of states an object goes through during its lifetime in response to events  The three key elements of a state machines are States, events, and transitions  State: Is a condition or situation during the life of an object which satisfies some condition, performs some activity, or waits for some event.  Event: The specification of a significant occurrence that has a location in time and space.  Transition: The movement from one state to another in response to an event.
  5. 5. Types of state machines i. Behavioral state machines ii. Protocol state machines Behavioral state machines :use states transitions and events to define the behavior of the classifier. States in this can specify one or more actions that execute when the state is entered, resided in or exited Example: Protocol state machines: They don’t have any behavior, simply define a usage protocol Example: interfaces and ports, have no behavior
  6. 6. State machines and Classes • State machines are most commonly used to model the dynamic behavior of Classes • Each class can have a single behavior state machine that models all the possible states, events, and transitions for all instances of that class • Each class can have one or more protocol state machines State machine diagrams A state machine diagram shows a state machine, emphasizing the flow of control from state to state. Example: A state machine diagram consists of  States  Transitions  Events
  7. 7. State machine diagrams Example: Idle Heatingcooling tooHot(desiredTemp) tooHot(desiredTemp) tooCold(desiredTemp) tooCold(desiredTemp) initial state Is a state machine diagram for home auto thermostat. initially it will be in idle state whenever the room temperature is too Hot it will move from idle state to Cooling state and whenever the room temperature is too Cold it will move from cooling state to Heating state
  8. 8. States A state is a condition or situation in the life of an object during which it satisfies some condition ,performs some activity or waits for some event. An object remains in a state for a finite amount of time. The state of an object varies over time A state has several parts 1.Name A textual string that distinguishes the state from other state 2.Entry/exit actions Actions executed on entering and exiting the state 3. Internal transitions Transitions that are handled without causing a change in state 4.Substates The nested structure of a state, involving disjoint or Example: concurrent sub states State name Entry actions Exit actions Internal transition Do activity Tracking entry/setMode(onTrack) exit/setMode(offTrack) newTraget/tracker.Acquire() do/followTraget
  9. 9. Transitions A Transition is a relationship between two states indicating that an object in the first state will perform certain actions and enter the second state when a specified event occurs. A transition has five parts Source State The state affected by the transition Event trigger The event whose reception by the object in the source state makes the transition eligible to fire Guard condition A Boolean expression that is evaluated when the transition is triggered by the reception of the event trigger Action An executable atomic computation that may directly act on the object Target state The state that is active after the completion of the transition.
  10. 10. Transitions Example: Idle Searching Engaging Tracking Engaging1 self-transition after(2 seconds)/send c.isAlive noise eventtrigger triggerless transition contact t.addTarget
  11. 11. Branching Transitions Directs the flow through the state machine according to conditions Example for Bank Loan payment
  12. 12. Events “Things that happen” are called events In the context of state machines, you use events to model the occurrence of a stimulus that can trigger a state transition Events may include signals, calls, the passing of time , or a change in state. Kinds of Events Signals: A signal represents a named object that is dispatched asynchronously by one object and then received by another Example: Call Events: A call event represents the dispatch of an operation, it is Synchronous Manual AutomaticstartAutopilot() Fig: Call Event
  13. 13. Time Event A time event is an event that represents the passage of time Example: Change event: A change event is an event that represents a change in state or the satisfaction of some condition Example: Idle Active after (2 seconds) /dropConnection() Idle Active when (11:49 PM) / selfTest()
  14. 14. Composite states A Composite State is a state that contains nested States. A Composite State may contain either Concurrent/orthogonal or Sequential/non orthogonal Sub states Simple/Non orthogonal Sub states: One region only Example: Consider the ATM system behavior This system might be in one of 3 basic states Idle, Active and Maintenance While Active, the behavior of the ATM follows a simple path, validate the customer, select a transaction, process the transaction and then print a receipt, after printing, the ATM returns to the idle state.
  15. 15. Idle Maintenance Validating Selecting Processing PrintingEntry/readCard Exit/ejectCard Card Inserted Cancel Active Initial state [more] [Finished] Maintain transition to composite state transition from composite state composite state nonorthogonal state transition from substate
  16. 16. Orthogonal composite states: Two or more regions ,Two or more state machines that execute in parallel in the context of the enclosing object. Idle Testing devices Commandwaiting Self diagnosis Maintenance Testing Commanding [continue] ----------------------------------------------------------------------------- keyPress [not continue] Maintian Orthogonal state
  17. 17. The Maintenance state is decomposed into two orthogonal regions, Testing and Commanding when control passes from the idle to the maintenance state, control then forks to two concurrent flows. Execution of these two orthogonal regions continues in parallel each nested state machine reaches its final state. If one orthogonal region reaches its final state before the other, control in that region waits as its final state. When both nested state machines reach their final states, control from the two orthogonal regions joins back into one flow.
  18. 18. Submachine States • A Submachine state is a special state that references another state machine • Its like a Subroutine call from one state machine to another • We use Submachine states to simplify Complex state machines • Submachine states can provide a reuse behavior History States: A history state allows a composite state that contains non orthogonal sub states to remember the last sub state that was active in it prior to the transition from the composite state. When a transaction enters a composite state, the action of the nested state machine starts over again at its initial state. An object remembers the last sub state that was active prior to leaving the composite state. Example: in modeling the behavior of an agent that does an unattended backup of computers across a network ,you’d like it to remember where it was in the process if it ever gets interrupted by a query from the operator.
  19. 19. shallow history Command Collecting Copying CleaningUp H shallow history state query BackingUp initial state for first entry
  20. 20. History States: You represent a shallow history state as a small circle containing the symbol H. If you want a transition to activate the last sub state, you show a transition from outside the composite state directly to the history state. suppose the object is in the BackingUp state and the Copying State, the query event is posted. Control leaves Copying and BackingUp and returns to the Command state. When the action of Command completes, the completion transition returns to the history state of the composite state BackingUp. Control passes back to the Copying state thus bypassing the Collecting state because Copying was the last Sub state active prior to the transition from the state BackingUp.
  21. 21. Summary/Glossary: • State Machine is a behavior that specifies the sequences of states an object goes through during its lifetime in response to events • State diagram that shows a state machine , state diagram address the dynamic view of a system State diagram contain • State: A condition or situation during the life of an object which it satisfies some condition, performs some activity, or waits for some event. • Transition: The movement from one state to another in response to an event. • Events: The specification of a significant occurrence that has a location in time and space. • Composite states: A Composite State is a state that contains nested States. Types of composite states • Orthogonal composite states: Two or more state machines that execute in parallel in the context of the enclosing object. • Non orthogonal composite state: A Sub state that cannot be held simultaneously with other sub states contained in the same composite state. • Submachine State is a special state that references another state machine • History State: A history state allows a composite state that contains non orthogonal sub states to remember the last sub state that was active in it prior to the transition from the composite state.
  22. 22. Quiz: 1) Using _________you can model the behavior of an individual object. a) Interaction Diagram b) Activity Diagram c) State machine Diagram d) Component Diagram 2) __________ Is a condition or situation during the life of an object which satisfies some condition, performs some activity, or waits for some event. a) State b) Event c) Transition d) Sub State 3) Examples of protocol state machines a) ports b) components c) Interfaces d) Nodes 4) ________________ Directs the flow through the state machine according to conditions A) Transition b) Branching Transition c) Guard condition d) none 5) ______________ is an asynchronous event a) Signal event b) Call event c) Time event d) Change of State event
  23. 23. Quiz: 6) Two or more state machines that execute in parallel in the context of the enclosing object is ____________ a) Orthogonal Composite state b) Non orthogonal Composite State 7) A______________ is a special state that references another state machine a) Sub state b) Composite state c) Submachine state d) none 8) _______ allows a composite state that contains non orthogonal sub states to remember the last sub state that was active in it prior to the transition from the composite state. a) History State b) orthogonal state c) Non orthogonal state d) Composite state
  24. 24. Key: 1) c 2) a 3) a, c 4) b 5) a 6) a 7) c 8) a
  25. 25. THANK YOU

×