1 / 17

State Diagrams

State Diagrams. What state are we in?. Introduction. What are the two main parts of a computer program? Data Algorithms We have previously emphasized how real-world information can be turned into data . How processing functions can be described with activity diagrams

nita
Download Presentation

State Diagrams

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 Diagrams What state are we in?

  2. Introduction • What are the two main parts of a computer program? • Data • Algorithms • We have previously emphasized • how real-world information can be turned into data. • How processing functions can be described with activity diagrams • We will now describe how the data might change when processed

  3. Object Oriented Programming • Object-Oriented programming seeks to solve a problem using data models taken from the problem domain. • Problem domain: the concepts and elements of the problem that is being solved. • An Object is simply a "thing" in the problem domain • When designing software, a programmer will listen to the problem description and then identify the objects in the domain.

  4. Object Oriented Programming A programmer is asked to write a program that will manage a persons DVD collection. The software should be able to search by actor or movie title or year or rating. What are the objects? A programmer is asked to write a flight simulator. The simulator shows a cockpit display to the user as the plane approaches a landing strip. What are the objects? A programmer is asked to write a web site identical to Facebook. What are the objects?

  5. More about Objects Example: Radio What is the state? What is the behavior? • An Object is a model of some thing. • An object has state (attribute data) • An object has behavior (actions it can take)

  6. More about Objects • We might say that the state includes: • Station (some number) • Power (on/off) • Band (AM/FM) • Volume (some number) • We might say that the behaviors include: • Select the station • Turn on/off • Switch band • Volume up/down

  7. Objects Change Over Time • Consider a program that allows users to control a virtual radio. When the software first starts, what are the values of the attributes? • Station, Power, Band, Volume • The user then does the following with the program: • The user turns on the radio • The user selects channel 98.9 • The user turns up the volume • What are the values of the attributes now? • Station, Power, Band, Volume • The point is, the values of the attributes change over time.

  8. The State of an Object • The State of an Object is a snapshot of the attribute values at one moment in time. • Recall the radio example. The start state is something like: • {Station:89, Power:Off, Band:FM, Volume:0} • A series of state changes then follow: • {Station:89, Power:On, Band:FM, Volume:0} • {Station:98.9, Power:Off, Band:FM, Volume:0} • {Station:89, Power:Off, Band:FM, Volume:1}

  9. State Diagrams • An activity diagram depicts the actions and their order when processing data • State diagrams depict how objects might change when processed. • Consider withdrawing money from an ATM: • State might involve: Checking, Approving, Rejecting. • Activities might involve: Insert Card, Enter PIN, Check balance, select withdraw, enter amount, take money, take card.

  10. UML State Diagrams the notation a state a transition from one state to another start state final state Part of the Unified Modeling Language Represents how objects are affected by processing activities

  11. Kindergarten 1st Grade 2nd Grade 3rd Grade 4th Grade 5thGrade 6th Grade Example: Elementary School Consider representing a student as a software object.

  12. What causes Transitions an EVENT Kindergarten 1st Grade fails standards satisfies matriculation standards potential events in software • a user’s action • triggered by another object • a timed event

  13. Traffic Light • What might the states of a traffic light be? • red / green / yellow / others? • What events cause a transition? • elapsed time • time of day • arrival of car • power outage

  14. at 2 a.m. after 10 sec. RED YELLOW FLASHING RED GREEN at 6 a.m. east/west car arrives after 5 sec. north/south car arrives + 2 sec. delay

  15. Machine Operating Safely state name entry / start motor exit / stop motor activities do / display warning light More Notation Activities can be included within states. Activities can be triggered when entering/exiting/in. entry -- activity upon incoming transition exit -- activity upon outgoing transition do -- continuous activity within state

  16. 1st Operand click digit (0 - 9) entry / oprnd1  0 do / display oprnd1 click digit (0 - 9) 1st Operand More Digits click digit (0 - 9) click C entry / oprnd1  oprnd1*10 + digit do / display oprnd1 click operator (+, -, *, /) click C 2nd Operand entry / op  operator; oprnd2 0 do / display oprnd2 Calculate Result click digit (0 - 9) click digit (0 - 9) entry / result  oprnd1 op oprnd2; oprnd1  0 do / display result 2nd Operand More Digits click C click = entry / oprnd2  oprnd2*10 + digit do / display oprnd2 Example - Calculator

  17. employee recommendation applicant inquiry applicant inquiry applicant inquiry Initial Stage Person of Interest applicant inquiry entry / create file; send application entry / create file; send application; respond to inquiry Awaiting Application Offer Pending receive incomplete app Still Awaiting entry / respond to inquiry entry / send offer app complete entry / return application app complete receive incomplete app Application Complete entry / send app to supervisors super requests interview super requests interview all supers reject Interview Pending entry / schedule interview exit / conduct interview renegotiate all supers reject super says hire offer accepted No Hire Hired offer rejected entry / send rejection Example Get a Job!

More Related