Presentation is loading. Please wait.

Presentation is loading. Please wait.

State Diagrams What state are we in?.

Similar presentations


Presentation on theme: "State Diagrams What state are we in?."— 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 An Object is a model of some thing.
An object has state (attribute data) An object has behavior (actions it can take) Example: Radio What is the state? What is the behavior?

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? 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 Part of the Unified Modeling Language
Represents how objects are affected by processing activities the notation a state a transition from one state to another start state final state

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

12 What causes Transitions
an EVENT satisfies matriculation standards Kindergarten 1st Grade fails 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 north/south car arrives
+ 2 sec. delay RED YELLOW GREEN FLASHING at 6 a.m. at 2 a.m. east/west car arrives after 10 sec. after 5 sec.

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

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

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


Download ppt "State Diagrams What state are we in?."

Similar presentations


Ads by Google