170 likes | 249 Views
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
E N D
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 • We will now describe how the data might change when processed
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.
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?
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)
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
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.
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}
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.
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
Kindergarten 1st Grade 2nd Grade 3rd Grade 4th Grade 5thGrade 6th Grade Example: Elementary School Consider representing a student as a software object.
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
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
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
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
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
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!