Presentation is loading. Please wait.

Presentation is loading. Please wait.

State Machines State diagrams SE-2030 Dr. Rob Hasker 1 Based on slides written by Dr. Mark L. Hornick Used with permission.

Similar presentations


Presentation on theme: "State Machines State diagrams SE-2030 Dr. Rob Hasker 1 Based on slides written by Dr. Mark L. Hornick Used with permission."— Presentation transcript:

1 State Machines State diagrams SE-2030 Dr. Rob Hasker 1 Based on slides written by Dr. Mark L. Hornick Used with permission.

2 Goals Sequence diagram: captures behavior of system Not much detail for individual classes The detail that’s there is spread across multiple diagrams State diagram Capture how object changes in response to events Especially useful for controllers SE-2030 Dr. Rob Hasker 2

3 SE-280 Dr. Rob Hasker 3 Example State Diagrams illustrate the dynamic behavior of a system (i.e. how a Controller functions) where events (perhaps from the UI) trigger actions and cause the system (Controller) to change its state.

4 A State Diagram for a light bulb controlled with a toggle switch SE-2030 Dr. Rob Hasker 4 The event flip switch to ‘1’ triggers the action current flows and the transition to the on state. The event flip switch to ‘0’ triggers the action current stops flowing and the transition to the off state.

5 A State Diagram for a light bulb controlled with a pushbutton switch SE-2030 Dr. Rob Hasker 5 The same event (button pressed) triggers different actions depending upon its current state.

6 Different events may also cause transitions to the same state SE-2030 Dr. Rob Hasker 6 Different events may cause transitions to different states However, state transitions must be deterministic; that is, the same event cannot cause a transition from one given state to more than one subsequent state.

7 The same event can cause different states to transition to the same state SE-2030 Dr. Rob Hasker 7 These state transitions are still deterministic since the same event does not cause a transition from one given state to more than one subsequent state.

8 In a complex system, different events may cause transitions to different states or to the same state SE-2030 Dr. Rob Hasker 8

9 It is common for an event to result in an action, but no state transition SE-2030 Dr. Rob Hasker 9

10 Initial and Final states may be indicated as follows SE-2030 Dr. Rob Hasker 10 Initial and Final states are special in that once a system leaves an Initial state, it cannot return to that state, and once a system achieves a Final state, it stays in that state.

11 Winter 2005/2006SE-280 Dr. Rob Hasker 11 A guard may be used to illustrate a condition that must be satisfied before a state transition can occur. The guard appears in brackets: [ ]

12 Demo: Describe the logic in a pushbutton lamp controller via a state diagram, and implement the controller as a State Machine SE-2030 Dr. Rob Hasker 12

13 State Diagrams can be used to help specify the dynamic logic implemented in Controller objects in response to events that the Controller receives SE-2030 Dr. Rob Hasker 13

14 Review State machines Capture state of instance of a class States, Transitions Events, Actions Deterministic/nondeterministic Initial, final states Guard Implementation SE-2030 Dr. Rob Hasker 14


Download ppt "State Machines State diagrams SE-2030 Dr. Rob Hasker 1 Based on slides written by Dr. Mark L. Hornick Used with permission."

Similar presentations


Ads by Google