Unformatted text preview:

CS211 Lecture: State Diagrams in UMLlast revised September 18, 2007Objectives:1. To show how to create and read State Diagrams Materials:1. Executable of Video Store project initial software to be given students2. Handout: code for Session class performSession() methodI. IntroductionA. We have drawn a distinction between the static aspects of a system and its dynamic aspects. The static aspects of a system have to do with its component parts and how they are related to one another; the dynamic aspects of a system have to do with how the components interact with one another and/or change state internally over time.B. We have been looking at one aspect of the dynamic behavior of a system - the way various objects interact to carry out the various use cases. We have looked at two ways of describing this:1. Sequence diagrams2. Communication diagramsC. We now want to look at another aspect of dynamic behavior - how an individual object changes state internally over time. 1. Example: As part of doing the domain analysis of a traffic light system, it is important to note that individual signals go through a series of states in a prescribed order - modeled by the following state diagram:DisplayingGreenDisplayingYellowDisplayingRed(Note: this is correct for the US but not for all countries in the world!)1An important “business rule” that any traffic light system must obey is that the light must be yellow for a certain minimum period of time (related to vehicle speed in the intersection) between displaying green and displaying red. Ensuring that a system exhibits this behavior is essential for safety.2. Note the difference between an interaction diagram and a state diagram - the former deals with how several objects work together to accomplish one use case; the latter deals with the internal state of one object, which may be affected by multiple use cases.Compare with a person’s internal state versus interactions with others. The “class session” use case involves several “Student” objects and a “Professor” object. Something that happens in class may affect the internal state of a student (e.g. getting back a test with a good (or for that matter bad) grade). The internal state of a “Student” object (e.g. sleepy) affects not only this use case, but also others like “chapel”.D. We will now consider a tool that can be used to model this aspect of the behavior of an object: The State Diagram. It can be used either for analysis (if our goal is to record how behavior actually transpires in a system we are modeling) or for design (if our goal is to describe a behavior we want to produce.)Note: UML 1 referred to these as statechart diagrams; UML 2 calls them State Machine Diagrams - sometimes shortened to State Diagrams.II. State DiagramsA. Often, while we analyze a system, we discover that some objects in a system undergo defined state transitions over time, which is an important part of the dynamic behavior of the system.1. Example: we just looked at an example of this in the domain of traffic lights. 2. What about our ATM example? ASKa) The ATM itself (represented by an ATM object in our case) goes through a series of states (off, on, serving a customer, etc.) b) Individual sessions pass through a series of states2c) Individual transactions also pass through a series of states.(Note that the objects that have this characteristic are often controller objects.)B. In such cases, it may prove helpful to develop a State Diagram, showing the states it passes through - especially if there is any complexity to the state transitions.1. Example: We will develop a state diagram for a session.a) Referring to the use case for a session, what distinct states can we identify? ASK(1) Reading card(2) Asking for PIN(3) Asking for transaction choice(4) Performing transaction(5) Ejecting card at the end of the session(6) Session finishedb) Further, the transitions between states for a session follow a fairly complex pattern - e.g.(1) After reading a card, we go either to asking for PIN or to ejecting card, depending on whether the card was readable.(2) After asking for PIN, we normally go to asking for a transaction choice; but we go to ejecting card if the customer presses cancel.(3) After asking for a transaction choice, we normally go to performing the transaction, but we go to ejecting card if the customer presses cancel.(4) After performing a transaction, we can go one of three ways:(a) To choosing transaction, if customer says he/she wants to do another.(b) To ejecting card, if customer says he/she doesn’t want to do another.(c) To session finished, if the card was retained due to too many invalid PINs.3c) PROJECT STATE DIAGRAM FOR SESSION FROM WEBd) We have already noted that there are other objects for which such a diagram would prove useful.ASKSHOW REMAINING STATE DIAGRAMS ON WEB2. In general, a state diagram is a useful analysis tool for:a) An object that is responsible for a use case, provided that the use case has enough internal complexity to warrant doing a state diagram. (If the use case consists of just a few steps, with no complex variation in sequencing, then a state diagram may not be warranted.)b) An object has complex internal states, even though it is not directly responsible for a use caseExample: In the case of the ATM simulation, the object representing the network connection to the bank would likely warrant a state diagram, because network connections typically pass through a series of states as they dialog with a peer on the other end. We have omitted that from the example, because we’ve avoided getting into the details of how the network connection works. A real system would, of course, have to deal with this.C. Another place where state diagrams are often useful is in the design of graphical user interfaces, as we noted in the previous series of lectures.1. The states correspond to the different visible states of the GUI - i.e. what screen etc. is being displayed and what buttons/menus are active.2. The transitions correspond to the various user gestures - i.e. options the user may choose.3. For your project, you will be creating a state diagram for the overall GUI for the video store software. Let’s spend a few moments now constructing a portion of it - the portion that pertains to checking out videos.DEMONSTRATION: Video Store GUI - Rent Tab4a) No ID typed - clicking “OK” ignoredb) Bad ID (type “bad”) entered - error messagec)


View Full Document

Gordon CPS 211 - LECTURE

Download LECTURE
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view LECTURE and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view LECTURE 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?