1 / 14

State Machines

State Machines. State diagrams. Based on slides written by Dr. Mark L. Hornick Used with permission. 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

steffi
Download Presentation

State Machines

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  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

  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. SE-280Dr. Rob Hasker

  4. A State Diagram for a light bulb controlled with a toggle switch The event flip switch to ‘1’ triggers the actioncurrent flows and the transition to the onstate. The event flip switch to ‘0’ triggers the actioncurrent stops flowingand the transition to the offstate. SE-2030 Dr. Rob Hasker

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

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

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

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

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

  10. Initial and Final states may be indicated as follows Initial and Final states are special in that once a system leaves an Initial state, it cannotreturn to that state, and once a system achieves a Final state, it stays in that state. SE-2030 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: [<guard>] SE-280Dr. Rob Hasker

  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

  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

  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

More Related