SlideShare a Scribd company logo
1 of 27
State Diagrams

                                   Chapter 5




Object-Oriented Software Systems Engineering – Chapter 5   Slide 1
Objectives

 In this chapter we will:
  Introduce the terms used with respect to state
   diagrams
  Discuss the context in which state diagrams are
   used
  Introduce substates
  Discuss concurrent state diagrams




Object-Oriented Software Systems Engineering – Chapter 5   Slide 2
Statechart Diagrams

  State diagrams describe the life of an object using
    three main elements:
       States of an object
       Transitions between states
       Events that trigger the transitions


  A state diagram or statechart specifies a state
    machine
       A state machine is described for a class
       Each object has it’s own state machine




Object-Oriented Software Systems Engineering – Chapter 5   Slide 3
Why Use Statechart Diagrams?

  Statecharts typically are used to describe state-dependent
    behaviour for an object
       An object responds differently to the same event depending on
        what state it is in
       Usually applied to objects but can be applied to any element
        that has behaviour
            Actors, use cases, methods, subsystems, systems

  Statecharts are typically used in conjunction with interaction
    diagrams (usually sequence diagrams)
       A statechart describes all events (and states and transitions for
        a single object)
       A sequence diagram describes the events for a single
        interaction across all objects involved

Object-Oriented Software Systems Engineering – Chapter 5            Slide 4
States

  Show what the dependencies are between the
   state of an object and its reactions to messages
   or other events
  State
       is a condition or situation during the life of an object
        within which it performs some activity, or waits for some
        events
       Has a name
       Has actions -- execute the state
       Has internal transitions -- transitions cause no change in
        a state
       substates -- the nested structure of a state involving
        disjoint or concurrent substates




Object-Oriented Software Systems Engineering – Chapter 5           Slide 5
States

  For example:



              At Work                         state name
   entry/unlock door                          action performed on entry to state
   do/prepare materials                       activity performed while in state
   telephone rings/answer telephone           action performed on arrival of named event
   include/lecture state                      name of a sub-state machine
   exit/lock door                             action performed on leaving state




Object-Oriented Software Systems Engineering – Chapter 5                         Slide 6
Initial and Final States

  The initial state of a state machine is indicated
    with a solid circle
       Known as a pseudo-state
       A transition from this state will show the first real state

  The final state of a state machine is shown as
    concentric circles
       A closed loop state machine does not have a final state;
        the object lives until the entire system terminates
       An open loop state machine represents an object that
        may terminate before the system terminates



Object-Oriented Software Systems Engineering – Chapter 5        Slide 7
Initial and Final States

  An example:



                  At Work             go home                    At Home



                                      go to work

                              die                          die




Object-Oriented Software Systems Engineering – Chapter 5                   Slide 8
Actions and Activities

  Action
       is an executable atomic computation
       includes operation calls, the creation or destruction of
        another object, or the sending of a signal to an object
       associated with transitions and during which an action is
        not interruptible -- e.g., entry, exit
  Activity is associated with states
       Non-atomic or ongoing computation
       May run to completion or continue indefinitely
       Will be terminated by an event that causes a transition
        from the state in which the activity is defined



Object-Oriented Software Systems Engineering – Chapter 5      Slide 9
Events

  An event signature is described as
    Event-name (comma-separated-parameter-list)
  Events appear in the internal transition
   compartment of a state or on a transition between
   states
  An event may be one of four types
       Signal event
            Corresponding to the arrival of an asynchronous message
              or signal
       Call event
            Corresponding to the arrival of a procedural call to an
              operation
       Time event
       Change event


Object-Oriented Software Systems Engineering – Chapter 5               Slide 10
Events

  A time event occurs after a specified time has
    elapsed
       Event name is specified as keyword after
       Parameter list is an expression evaluating to a time
        interval
            after(10 seconds after state “At Work” is entered)
       No specified start time implies “since entry to the current
        state”
            after(2 seconds)




Object-Oriented Software Systems Engineering – Chapter 5          Slide 11
Events

  A change event occurs whenever a specified
    condition is met
       Event name is specified as keyword when
       Parameter list is a boolean expression
       The event occurs when both of the following conditions
        are met, irrespective of the order when they happen
            The expression evaluates to true
            The object is in the required state
       For example
            when (state = At Work)
            when (date = January 1 2007)




Object-Oriented Software Systems Engineering – Chapter 5      Slide 12
Transitions

 A transition is drawn as an arrow between states
   annotated with a transition string
  The transition string denotes the event and
    consequent action
  Only one form of arrowhead is used on statecharts
            The distinction between call events and signal events must be
              deducted from elsewhere e.g. an interaction diagram


 A transition string is described as
  Event-signature [guard-condition]/action-expression^object.message
  If the guard condition is met the transition occurs immediately



Object-Oriented Software Systems Engineering – Chapter 5            Slide 13
Transitions

  A transition whose string contains neither an
    event signature nor a guard condition is said to be
    unlabeled
       Occurs immediately
       May still carry an action expression




Object-Oriented Software Systems Engineering – Chapter 5   Slide 14
Transitions

  A transition is triggered when its event occurs
     If the guard condition is met, the transition is fired
     If the condition is not met the event is discarded
            The guard condition is checked only once

  If there is no guard condition, triggering will
   always cause firing
  Note the distinction between a guard condition
   and a change event
       A guard condition is evaluated once, when the
        associated event occurs
       A change event occurs whenever its associated
        condition is met
            Behaviour is as if the condition were being continually
              evaluated


Object-Oriented Software Systems Engineering – Chapter 5               Slide 15
State Diagrams notation



Initial state          event                                                       final state
                                         name


                Invoice                                                 Invoice
                created                      paying                    destroyed
                               Unpaid                           Paid



         transition
                                    state




     Object-Oriented Software Systems Engineering – Chapter 5                      Slide 16
State Diagram Example

  This shows the state of an object myBkCpy from a BookCopy class

                on loan                  return()                 on the shelf
      entry / myBkCpy.borrow()                             entry / myBkCpy.return()
                                         borrow()

    Entry action : any action that is marked as linked to the entry action is
    executed whenever the given state is entered via a transition


                 on loan                   return()                on the shelf
       exit / myBkCpy.returned()                            exit / myBkCpy.borrowed()
                                           borrow()

   Exit action : any action that is marked as linked to the exit action is
   executed whenever the state is left via a transition

Object-Oriented Software Systems Engineering – Chapter 5                     Slide 17
A Class of BookCopy



              BookCopy


 onShelf : Boolean                                   value := ‘Y’   on the shelf
                                                     value := ‘N’   on loan

 return()                                            action / onShelf=‘Y’

 borrow()                                            action / onShelf=‘N’




Object-Oriented Software Systems Engineering – Chapter 5                 Slide 18
State Diagram Example
                                   get first item                        all items
                                                                          in stock
                                           [all items checked &&
  *[all items checked]
                                           all items available]
  get next item              Checking                                     Dispatching
                                           Dispatch items
                             do / check
                             Item
                                                                 b le]    do / initiate
             [all items checked                              aila         delivery
                                                           av d
             && some items not
                                                      tems eive
             in stock]                            ll i rec
                                                [a m                         delivery
             Order Item                           Ite

some items                   Ordering                                    Delivering
not in stock                                          cancelled
                         Exit/ Item received                             entry / deliver
                         do / order Item                                 Items


                                                      Canceling
                                                     do / Remove
                                                     Item
Object-Oriented Software Systems Engineering – Chapter 5                      Slide 19
State Diagram - Nested States



               event-1                                     Super-state
    A                         B
                                                             event-1
                                                      A                   B

event-2                     event-2

                  C                                                 event-2


                                                                C




Object-Oriented Software Systems Engineering – Chapter 5                      Slide 20
State Diagram Example including substates
                                     get first item

       *[all items checked]
                                           [all items checked && all items available]
       get next item
                         Checking          Dispatch items             Dispatching
                           do / check                                     do / initiate
                           Item                                    ble]   delivery
                                                               a
                                                          v ail
      [all items checked &&                           ms a ved
      some items not in stock]                   l ite ecei
      Order item                              [al m r                              delivery
                                                Ite

                            Ordering
                        Exit/ Item received
                        do / order Item



                                                      Canceling             Delivering
                               cancelled
                                                      do / Remove         entry / deliver
                                                      Item                Items
Object-Oriented Software Systems Engineering – Chapter 5                          Slide 21
Concurrent State models

                                                      B
                                                                       s       Finishing
       Starting
                                        A                      C



                                                      E                T
Explicit control
branching(fork)
                                        D                          G



                                                      F



          Orthogonal Components and Concurrency
                    shown separated by dashed line
                       supports concurrency
          Objects must be in only one state from each of the
              orthogonal components
    Object-Oriented Software Systems Engineering – Chapter 5               Slide 22
Concurrent State Models

 Three different ways for orthogonal components to
   communicate:


  Broadcast Events
  Propogated Events
  IN operators




Object-Oriented Software Systems Engineering – Chapter 5   Slide 23
Concurrent State Models

  Broadcast events
       events that more than one orthogonal component
        accepts
       For example an event T1 is sent to all active orthogonal
        components it need not be acted on by all components
            what happens if component S1 is in state A, S2 is in state E
              and S3 is in state G when a T1 event occurs?
            what happens if S1 is in state A and S2 is in state D when
              the event T1 occurs?




Object-Oriented Software Systems Engineering – Chapter 5            Slide 24
Concurrent State Models

  Propagated events are indicated with the caret
    following the event name (and optional parameters
    and guard)


  IN operators are used as a guard on transition T4.
    This allows the S3 component to take the
    transition T4 only if S2 is currently in state D




Object-Oriented Software Systems Engineering – Chapter 5   Slide 25
Concurrent State Models
                                             S

          S1        H                                             S3
                            T1
                                      B


                                                           F
                    A

                                                                T4[IN(D)]
                                  C
              T2^T3(x,y,z)                                                 T5
                                                           G


         S2             H                                      T3(a,b,c)
                                                                            T6
                                                           H
                D                T3(a,b,c)


               T1                 E




Object-Oriented Software Systems Engineering – Chapter 5                   Slide 26
Summary

 In this chapter we have:
  Introduced the terms used with respect to state
   diagrams
  Discussed the context in which state diagrams are
   used
  Introduced substates
  Discussed concurrent state diagrams




Object-Oriented Software Systems Engineering – Chapter 5   Slide 27

More Related Content

What's hot

Unit 1( modelling concepts & class modeling)
Unit  1( modelling concepts & class modeling)Unit  1( modelling concepts & class modeling)
Unit 1( modelling concepts & class modeling)Manoj Reddy
 
Activity Diagram
Activity DiagramActivity Diagram
Activity DiagramAshesh R
 
Object Oriented Analysis and Design
Object Oriented Analysis and DesignObject Oriented Analysis and Design
Object Oriented Analysis and DesignHaitham El-Ghareeb
 
Coupling and cohesion
Coupling and cohesionCoupling and cohesion
Coupling and cohesionSutha31
 
Object oriented-systems-development-life-cycle ppt
Object oriented-systems-development-life-cycle pptObject oriented-systems-development-life-cycle ppt
Object oriented-systems-development-life-cycle pptKunal Kishor Nirala
 
State Machine Diagram
State Machine DiagramState Machine Diagram
State Machine DiagramNiloy Rocker
 
Activity diagram tutorial
Activity diagram tutorialActivity diagram tutorial
Activity diagram tutorialDeclan Chellar
 
Dynamic and Static Modeling
Dynamic and Static ModelingDynamic and Static Modeling
Dynamic and Static ModelingSaurabh Kumar
 
Agile Development | Agile Process Models
Agile Development | Agile Process ModelsAgile Development | Agile Process Models
Agile Development | Agile Process ModelsAhsan Rahim
 
Interaction Modeling
Interaction ModelingInteraction Modeling
Interaction ModelingHemant Sharma
 
Sequence diagram
Sequence diagramSequence diagram
Sequence diagramRahul Pola
 
Uml Activity Diagram
Uml Activity DiagramUml Activity Diagram
Uml Activity DiagramNiloy Rocker
 
7. sequence and collaboration diagrams
7. sequence and collaboration diagrams7. sequence and collaboration diagrams
7. sequence and collaboration diagramsAPU
 

What's hot (20)

Activity diagram
Activity diagramActivity diagram
Activity diagram
 
Unit 1( modelling concepts & class modeling)
Unit  1( modelling concepts & class modeling)Unit  1( modelling concepts & class modeling)
Unit 1( modelling concepts & class modeling)
 
Activity Diagram
Activity DiagramActivity Diagram
Activity Diagram
 
Activity diagram
Activity diagramActivity diagram
Activity diagram
 
Object Oriented Analysis and Design
Object Oriented Analysis and DesignObject Oriented Analysis and Design
Object Oriented Analysis and Design
 
Coupling and cohesion
Coupling and cohesionCoupling and cohesion
Coupling and cohesion
 
Object oriented-systems-development-life-cycle ppt
Object oriented-systems-development-life-cycle pptObject oriented-systems-development-life-cycle ppt
Object oriented-systems-development-life-cycle ppt
 
Introduction to UML
Introduction to UMLIntroduction to UML
Introduction to UML
 
State Machine Diagram
State Machine DiagramState Machine Diagram
State Machine Diagram
 
Activity diagrams
Activity diagramsActivity diagrams
Activity diagrams
 
Activity diagram tutorial
Activity diagram tutorialActivity diagram tutorial
Activity diagram tutorial
 
Dynamic and Static Modeling
Dynamic and Static ModelingDynamic and Static Modeling
Dynamic and Static Modeling
 
Agile Development | Agile Process Models
Agile Development | Agile Process ModelsAgile Development | Agile Process Models
Agile Development | Agile Process Models
 
Class based modeling
Class based modelingClass based modeling
Class based modeling
 
Interaction Modeling
Interaction ModelingInteraction Modeling
Interaction Modeling
 
Diagrams
DiagramsDiagrams
Diagrams
 
Sequence diagram
Sequence diagramSequence diagram
Sequence diagram
 
State Diagram
State DiagramState Diagram
State Diagram
 
Uml Activity Diagram
Uml Activity DiagramUml Activity Diagram
Uml Activity Diagram
 
7. sequence and collaboration diagrams
7. sequence and collaboration diagrams7. sequence and collaboration diagrams
7. sequence and collaboration diagrams
 

Similar to State Diagrams Chapter Explained

STATE DIAGRAM.pptx
STATE DIAGRAM.pptxSTATE DIAGRAM.pptx
STATE DIAGRAM.pptxssuser2d043c
 
Software System Engineering - Chapter 14
Software System Engineering - Chapter 14Software System Engineering - Chapter 14
Software System Engineering - Chapter 14Fadhil Ismail
 
Lecture 13 requirements modeling - flow & behavior (2)
Lecture 13   requirements modeling - flow &  behavior (2)Lecture 13   requirements modeling - flow &  behavior (2)
Lecture 13 requirements modeling - flow & behavior (2)IIUI
 
discrete-event-simulation-190410063238.pptx
discrete-event-simulation-190410063238.pptxdiscrete-event-simulation-190410063238.pptx
discrete-event-simulation-190410063238.pptxubaidullah75790
 
SE_Lec 09_ UML Behaviour Diagrams
SE_Lec 09_ UML Behaviour DiagramsSE_Lec 09_ UML Behaviour Diagrams
SE_Lec 09_ UML Behaviour DiagramsAmr E. Mohamed
 
Singleton Object Management
Singleton Object ManagementSingleton Object Management
Singleton Object Managementppd1961
 
ITE 1122_ Event Handling.pptx
ITE 1122_ Event Handling.pptxITE 1122_ Event Handling.pptx
ITE 1122_ Event Handling.pptxudithaisur
 
event-handling.pptx
event-handling.pptxevent-handling.pptx
event-handling.pptxGood657694
 
SE18_Lec 10_ UML Behaviour and Interaction Diagrams
SE18_Lec 10_ UML Behaviour and Interaction DiagramsSE18_Lec 10_ UML Behaviour and Interaction Diagrams
SE18_Lec 10_ UML Behaviour and Interaction DiagramsAmr E. Mohamed
 
Dr Jammi Ashok - Introduction to Java Material (OOPs)
 Dr Jammi Ashok - Introduction to Java Material (OOPs) Dr Jammi Ashok - Introduction to Java Material (OOPs)
Dr Jammi Ashok - Introduction to Java Material (OOPs)jammiashok123
 
Aaai 2011 event processing tutorial
Aaai 2011 event processing tutorialAaai 2011 event processing tutorial
Aaai 2011 event processing tutorialOpher Etzion
 
Declarative presentations UIKonf
Declarative presentations UIKonfDeclarative presentations UIKonf
Declarative presentations UIKonfNataliya Patsovska
 

Similar to State Diagrams Chapter Explained (20)

STATE DIAGRAM.pptx
STATE DIAGRAM.pptxSTATE DIAGRAM.pptx
STATE DIAGRAM.pptx
 
Ooad ch 5
Ooad ch 5Ooad ch 5
Ooad ch 5
 
Software System Engineering - Chapter 14
Software System Engineering - Chapter 14Software System Engineering - Chapter 14
Software System Engineering - Chapter 14
 
Lecture 13 requirements modeling - flow & behavior (2)
Lecture 13   requirements modeling - flow &  behavior (2)Lecture 13   requirements modeling - flow &  behavior (2)
Lecture 13 requirements modeling - flow & behavior (2)
 
Seminar State Chart1
Seminar State Chart1Seminar State Chart1
Seminar State Chart1
 
discrete-event-simulation-190410063238.pptx
discrete-event-simulation-190410063238.pptxdiscrete-event-simulation-190410063238.pptx
discrete-event-simulation-190410063238.pptx
 
States machine
States machineStates machine
States machine
 
SE_Lec 09_ UML Behaviour Diagrams
SE_Lec 09_ UML Behaviour DiagramsSE_Lec 09_ UML Behaviour Diagrams
SE_Lec 09_ UML Behaviour Diagrams
 
Ooad 3
Ooad 3Ooad 3
Ooad 3
 
Singleton Object Management
Singleton Object ManagementSingleton Object Management
Singleton Object Management
 
Step types
Step typesStep types
Step types
 
ITE 1122_ Event Handling.pptx
ITE 1122_ Event Handling.pptxITE 1122_ Event Handling.pptx
ITE 1122_ Event Handling.pptx
 
Jar chapter 4, part 1
Jar chapter 4, part 1Jar chapter 4, part 1
Jar chapter 4, part 1
 
Discrete event-simulation
Discrete event-simulationDiscrete event-simulation
Discrete event-simulation
 
event-handling.pptx
event-handling.pptxevent-handling.pptx
event-handling.pptx
 
IoT in salsa Serverless
IoT in salsa ServerlessIoT in salsa Serverless
IoT in salsa Serverless
 
SE18_Lec 10_ UML Behaviour and Interaction Diagrams
SE18_Lec 10_ UML Behaviour and Interaction DiagramsSE18_Lec 10_ UML Behaviour and Interaction Diagrams
SE18_Lec 10_ UML Behaviour and Interaction Diagrams
 
Dr Jammi Ashok - Introduction to Java Material (OOPs)
 Dr Jammi Ashok - Introduction to Java Material (OOPs) Dr Jammi Ashok - Introduction to Java Material (OOPs)
Dr Jammi Ashok - Introduction to Java Material (OOPs)
 
Aaai 2011 event processing tutorial
Aaai 2011 event processing tutorialAaai 2011 event processing tutorial
Aaai 2011 event processing tutorial
 
Declarative presentations UIKonf
Declarative presentations UIKonfDeclarative presentations UIKonf
Declarative presentations UIKonf
 

More from APU

01 introduction to_module
01 introduction to_module01 introduction to_module
01 introduction to_moduleAPU
 
. 1. introduction to object orientation
. 1. introduction to object orientation. 1. introduction to object orientation
. 1. introduction to object orientationAPU
 
. 01 introduction_to_module
. 01 introduction_to_module. 01 introduction_to_module
. 01 introduction_to_moduleAPU
 
9. oo languages
9. oo languages9. oo languages
9. oo languagesAPU
 
8. design patterns
8. design patterns8. design patterns
8. design patternsAPU
 
6. activity diagrams
6. activity diagrams6. activity diagrams
6. activity diagramsAPU
 
5. state diagrams
5. state diagrams5. state diagrams
5. state diagramsAPU
 
4. class diagrams using uml
4. class diagrams using uml4. class diagrams using uml
4. class diagrams using umlAPU
 
3. use cases
3. use cases3. use cases
3. use casesAPU
 
01 introduction to_module
01 introduction to_module01 introduction to_module
01 introduction to_moduleAPU
 
. 9. oo languages
. 9. oo languages. 9. oo languages
. 9. oo languagesAPU
 
08 aggregation and collection classes
08  aggregation and collection classes08  aggregation and collection classes
08 aggregation and collection classesAPU
 
. 8. design patterns
. 8. design patterns. 8. design patterns
. 8. design patternsAPU
 
. 5. state diagrams
. 5. state diagrams. 5. state diagrams
. 5. state diagramsAPU
 
. 4. class diagrams using uml
. 4. class diagrams using uml. 4. class diagrams using uml
. 4. class diagrams using umlAPU
 
. 2. introduction to uml
. 2. introduction to uml. 2. introduction to uml
. 2. introduction to umlAPU
 
. 01 introduction_to_module
. 01 introduction_to_module. 01 introduction_to_module
. 01 introduction_to_moduleAPU
 
14 file handling
14 file handling14 file handling
14 file handlingAPU
 
13 gui development
13 gui development13 gui development
13 gui developmentAPU
 
10 exceptionsin java
10 exceptionsin java10 exceptionsin java
10 exceptionsin javaAPU
 

More from APU (20)

01 introduction to_module
01 introduction to_module01 introduction to_module
01 introduction to_module
 
. 1. introduction to object orientation
. 1. introduction to object orientation. 1. introduction to object orientation
. 1. introduction to object orientation
 
. 01 introduction_to_module
. 01 introduction_to_module. 01 introduction_to_module
. 01 introduction_to_module
 
9. oo languages
9. oo languages9. oo languages
9. oo languages
 
8. design patterns
8. design patterns8. design patterns
8. design patterns
 
6. activity diagrams
6. activity diagrams6. activity diagrams
6. activity diagrams
 
5. state diagrams
5. state diagrams5. state diagrams
5. state diagrams
 
4. class diagrams using uml
4. class diagrams using uml4. class diagrams using uml
4. class diagrams using uml
 
3. use cases
3. use cases3. use cases
3. use cases
 
01 introduction to_module
01 introduction to_module01 introduction to_module
01 introduction to_module
 
. 9. oo languages
. 9. oo languages. 9. oo languages
. 9. oo languages
 
08 aggregation and collection classes
08  aggregation and collection classes08  aggregation and collection classes
08 aggregation and collection classes
 
. 8. design patterns
. 8. design patterns. 8. design patterns
. 8. design patterns
 
. 5. state diagrams
. 5. state diagrams. 5. state diagrams
. 5. state diagrams
 
. 4. class diagrams using uml
. 4. class diagrams using uml. 4. class diagrams using uml
. 4. class diagrams using uml
 
. 2. introduction to uml
. 2. introduction to uml. 2. introduction to uml
. 2. introduction to uml
 
. 01 introduction_to_module
. 01 introduction_to_module. 01 introduction_to_module
. 01 introduction_to_module
 
14 file handling
14 file handling14 file handling
14 file handling
 
13 gui development
13 gui development13 gui development
13 gui development
 
10 exceptionsin java
10 exceptionsin java10 exceptionsin java
10 exceptionsin java
 

State Diagrams Chapter Explained

  • 1. State Diagrams Chapter 5 Object-Oriented Software Systems Engineering – Chapter 5 Slide 1
  • 2. Objectives In this chapter we will:  Introduce the terms used with respect to state diagrams  Discuss the context in which state diagrams are used  Introduce substates  Discuss concurrent state diagrams Object-Oriented Software Systems Engineering – Chapter 5 Slide 2
  • 3. Statechart Diagrams  State diagrams describe the life of an object using three main elements:  States of an object  Transitions between states  Events that trigger the transitions  A state diagram or statechart specifies a state machine  A state machine is described for a class  Each object has it’s own state machine Object-Oriented Software Systems Engineering – Chapter 5 Slide 3
  • 4. Why Use Statechart Diagrams?  Statecharts typically are used to describe state-dependent behaviour for an object  An object responds differently to the same event depending on what state it is in  Usually applied to objects but can be applied to any element that has behaviour  Actors, use cases, methods, subsystems, systems  Statecharts are typically used in conjunction with interaction diagrams (usually sequence diagrams)  A statechart describes all events (and states and transitions for a single object)  A sequence diagram describes the events for a single interaction across all objects involved Object-Oriented Software Systems Engineering – Chapter 5 Slide 4
  • 5. States  Show what the dependencies are between the state of an object and its reactions to messages or other events  State  is a condition or situation during the life of an object within which it performs some activity, or waits for some events  Has a name  Has actions -- execute the state  Has internal transitions -- transitions cause no change in a state  substates -- the nested structure of a state involving disjoint or concurrent substates Object-Oriented Software Systems Engineering – Chapter 5 Slide 5
  • 6. States  For example: At Work state name entry/unlock door action performed on entry to state do/prepare materials activity performed while in state telephone rings/answer telephone action performed on arrival of named event include/lecture state name of a sub-state machine exit/lock door action performed on leaving state Object-Oriented Software Systems Engineering – Chapter 5 Slide 6
  • 7. Initial and Final States  The initial state of a state machine is indicated with a solid circle  Known as a pseudo-state  A transition from this state will show the first real state  The final state of a state machine is shown as concentric circles  A closed loop state machine does not have a final state; the object lives until the entire system terminates  An open loop state machine represents an object that may terminate before the system terminates Object-Oriented Software Systems Engineering – Chapter 5 Slide 7
  • 8. Initial and Final States  An example: At Work go home At Home go to work die die Object-Oriented Software Systems Engineering – Chapter 5 Slide 8
  • 9. Actions and Activities  Action  is an executable atomic computation  includes operation calls, the creation or destruction of another object, or the sending of a signal to an object  associated with transitions and during which an action is not interruptible -- e.g., entry, exit  Activity is associated with states  Non-atomic or ongoing computation  May run to completion or continue indefinitely  Will be terminated by an event that causes a transition from the state in which the activity is defined Object-Oriented Software Systems Engineering – Chapter 5 Slide 9
  • 10. Events  An event signature is described as Event-name (comma-separated-parameter-list)  Events appear in the internal transition compartment of a state or on a transition between states  An event may be one of four types  Signal event  Corresponding to the arrival of an asynchronous message or signal  Call event  Corresponding to the arrival of a procedural call to an operation  Time event  Change event Object-Oriented Software Systems Engineering – Chapter 5 Slide 10
  • 11. Events  A time event occurs after a specified time has elapsed  Event name is specified as keyword after  Parameter list is an expression evaluating to a time interval  after(10 seconds after state “At Work” is entered)  No specified start time implies “since entry to the current state”  after(2 seconds) Object-Oriented Software Systems Engineering – Chapter 5 Slide 11
  • 12. Events  A change event occurs whenever a specified condition is met  Event name is specified as keyword when  Parameter list is a boolean expression  The event occurs when both of the following conditions are met, irrespective of the order when they happen  The expression evaluates to true  The object is in the required state  For example  when (state = At Work)  when (date = January 1 2007) Object-Oriented Software Systems Engineering – Chapter 5 Slide 12
  • 13. Transitions A transition is drawn as an arrow between states annotated with a transition string  The transition string denotes the event and consequent action  Only one form of arrowhead is used on statecharts  The distinction between call events and signal events must be deducted from elsewhere e.g. an interaction diagram A transition string is described as  Event-signature [guard-condition]/action-expression^object.message  If the guard condition is met the transition occurs immediately Object-Oriented Software Systems Engineering – Chapter 5 Slide 13
  • 14. Transitions  A transition whose string contains neither an event signature nor a guard condition is said to be unlabeled  Occurs immediately  May still carry an action expression Object-Oriented Software Systems Engineering – Chapter 5 Slide 14
  • 15. Transitions  A transition is triggered when its event occurs  If the guard condition is met, the transition is fired  If the condition is not met the event is discarded  The guard condition is checked only once  If there is no guard condition, triggering will always cause firing  Note the distinction between a guard condition and a change event  A guard condition is evaluated once, when the associated event occurs  A change event occurs whenever its associated condition is met  Behaviour is as if the condition were being continually evaluated Object-Oriented Software Systems Engineering – Chapter 5 Slide 15
  • 16. State Diagrams notation Initial state event final state name Invoice Invoice created paying destroyed Unpaid Paid transition state Object-Oriented Software Systems Engineering – Chapter 5 Slide 16
  • 17. State Diagram Example This shows the state of an object myBkCpy from a BookCopy class on loan return() on the shelf entry / myBkCpy.borrow() entry / myBkCpy.return() borrow() Entry action : any action that is marked as linked to the entry action is executed whenever the given state is entered via a transition on loan return() on the shelf exit / myBkCpy.returned() exit / myBkCpy.borrowed() borrow() Exit action : any action that is marked as linked to the exit action is executed whenever the state is left via a transition Object-Oriented Software Systems Engineering – Chapter 5 Slide 17
  • 18. A Class of BookCopy BookCopy onShelf : Boolean value := ‘Y’ on the shelf value := ‘N’ on loan return() action / onShelf=‘Y’ borrow() action / onShelf=‘N’ Object-Oriented Software Systems Engineering – Chapter 5 Slide 18
  • 19. State Diagram Example get first item all items in stock [all items checked && *[all items checked] all items available] get next item Checking Dispatching Dispatch items do / check Item b le] do / initiate [all items checked aila delivery av d && some items not tems eive in stock] ll i rec [a m delivery Order Item Ite some items Ordering Delivering not in stock cancelled Exit/ Item received entry / deliver do / order Item Items Canceling do / Remove Item Object-Oriented Software Systems Engineering – Chapter 5 Slide 19
  • 20. State Diagram - Nested States event-1 Super-state A B event-1 A B event-2 event-2 C event-2 C Object-Oriented Software Systems Engineering – Chapter 5 Slide 20
  • 21. State Diagram Example including substates get first item *[all items checked] [all items checked && all items available] get next item Checking Dispatch items Dispatching do / check do / initiate Item ble] delivery a v ail [all items checked && ms a ved some items not in stock] l ite ecei Order item [al m r delivery Ite Ordering Exit/ Item received do / order Item Canceling Delivering cancelled do / Remove entry / deliver Item Items Object-Oriented Software Systems Engineering – Chapter 5 Slide 21
  • 22. Concurrent State models B s Finishing Starting A C E T Explicit control branching(fork) D G F  Orthogonal Components and Concurrency  shown separated by dashed line  supports concurrency  Objects must be in only one state from each of the orthogonal components Object-Oriented Software Systems Engineering – Chapter 5 Slide 22
  • 23. Concurrent State Models Three different ways for orthogonal components to communicate:  Broadcast Events  Propogated Events  IN operators Object-Oriented Software Systems Engineering – Chapter 5 Slide 23
  • 24. Concurrent State Models  Broadcast events  events that more than one orthogonal component accepts  For example an event T1 is sent to all active orthogonal components it need not be acted on by all components  what happens if component S1 is in state A, S2 is in state E and S3 is in state G when a T1 event occurs?  what happens if S1 is in state A and S2 is in state D when the event T1 occurs? Object-Oriented Software Systems Engineering – Chapter 5 Slide 24
  • 25. Concurrent State Models  Propagated events are indicated with the caret following the event name (and optional parameters and guard)  IN operators are used as a guard on transition T4. This allows the S3 component to take the transition T4 only if S2 is currently in state D Object-Oriented Software Systems Engineering – Chapter 5 Slide 25
  • 26. Concurrent State Models S S1 H S3 T1 B F A T4[IN(D)] C T2^T3(x,y,z) T5 G S2 H T3(a,b,c) T6 H D T3(a,b,c) T1 E Object-Oriented Software Systems Engineering – Chapter 5 Slide 26
  • 27. Summary In this chapter we have:  Introduced the terms used with respect to state diagrams  Discussed the context in which state diagrams are used  Introduced substates  Discussed concurrent state diagrams Object-Oriented Software Systems Engineering – Chapter 5 Slide 27

Editor's Notes

  1. 1