Unformatted text preview:

CS211 Lecture: Modeling Dynamic Behaviors of Systems; Interaction Diagrams in UMLlast revised September 18, 2007Objectives:1. To introduce the notion of dynamic analysis2. To show how to create and read Sequence Diagrams3. To show how to create and read Communication Diagrams Materials:1. Handout of baseball double play Sequence and Communication Diagrams2. Ability to project ATM example system3. Handout of Session Communication diagramsI. IntroductionA. In trying to understand any system, there are really two aspects of the system to be considered: its static aspects 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.Example: Suppose we were analyzing the game of baseball - in particular, the way that a team functions when it is on defense (out in the field)1. The static aspects of this system include things like the fact that there are 9 players on the field at a time, and the various positions that they play. In fact, if you were watching a baseball game, this is mostly what you would see - most of the time the players are in their positions, ready for a ball to come their way.2. The dynamic aspects of this system include the various interactions (“plays”) that occur under various circumstances. For example, one such interaction is called a “double play”, which can happen when there is a runner on first base and the batter hits a ground ball It commonly takes one of two forms:a) If the ball is hit between second and third bases, then the shortstop runs to the ball while the second baseman runs toward second base. The shortstop fields the ball and throws it to the second baseman, who in turn throws it to the first baseman. In baseball jargon, this is called a “6-4-3 double play”.1b) On the other hand, if the ball is hit between first and second bases, then the second baseman fields the ball and throws it to the shortstop (covering second) who in turn throws it to first. In baseball jargon, this is called a “4-6-3 double play”.B. Thus far, we have largely discussed static aspects of systems - e.g. a class diagram represents the (static) relationship between the classes comprising a system, etc. CRC cards are developed by thinking through the dynamic behavior of a system, but basically record static information (who is responsible for what; who collaborates with whom, etc.)C. We will now consider a couple tools that can be used to model the interaction of objects to accomplish a use case. Later, we will look at a tool that can be used to model changes of state of the system as a whole or an individual object in it.1. Each 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.)2. UML calls these diagrams Interaction Diagrams, of which there are two types:a) Sequence Diagramsb) Communication Diagrams (UML 2 name - UML 1 called them colllaboration diagrams.)c) The two types of diagram are equivalent, in the sense that either one can be constructed from information in the other. 3. For example, here are two diagrams that show a “6-4-3” double play: One is a sequence diagram; the other a communication diagram. (These are more the kind of diagram that would be produced during analysis than a diagram that would be produced to design software.)(HANDOUT)2:Shortstop:SecondBaseman:Runner:Batterhits ball tothrows ball toputs out:FirstBasemanthrows ball toputs out:Shortstop:SecondBaseman:Runner{destroyed}:Batter{destroyed}1: hits ball to2: throws ball to3.1 puts out:FirstBaseman3: throws ball to2.1 puts outII. Sequence DiagramsA. I will focus first on the sequence diagram, because I think it is the easier of the two for a beginner to understand and construct. PROJECT: Sequence diagram for Session.3B. General observations:1. An interaction diagram (of either type) depicts a society of objects that work together to carry out a particular use case. Thus, in general, there will be an interaction diagram for each use case.2. The vertical dimension in a sequence diagram is time. The interaction starts at the top of the diagram, and progresses through time to the bottom.3. The boxes in the interaction diagram stand for objects. Note that UML uses very similar notation for objects and for classes in diagrams - both are represented by rectangles. As you recall from an earlier lecture, two things distinguish the symbol for an object from that for a class:a) An object has both an object name and a class name. These are written separated by a colon - e.g. joe: Student. In a UML diagram, it is common for an object to be anonymous - in which case the box contains just the class name, preceded by a colon. (If there were a name followed by a colon, it would be an object name of anonymous class.)b) As we have already noted, in UML object diagrams, it is common to underline the object:class name. (This is not done consistently, though; in fact, I had to add this to the diagram I have handed out, because the drawing tool I used to produce it doesn’t provide for this!)c) Underneath each object is a dotted line called its lifeline. The lifeline indicates when the object is in existence.(1) If the lifeline extends the entire length of the diagram, it means that the object exists before the interaction begins and continues to exist after it ends.(a) Examples from double-playASKShortstop, Second Baseman, First Baseman(b) Examples from ATM SessionASKCardReader, ATM, CustomerConsole4(2) If the lifeline begins part-way through the interaction, it indicates that the corresponding object is created during the interaction. Likewise, if the lifeline terminates in an “X” before the end of the interaction, this indicates that the corresponding object is destroyed during the interaction.(a) Examples from double play:ASKBatter and Runner are both destroyed in the interaction(b) Examples from sessionSession, Transaction are both created and destroyed in the interaction(c) It is also possible - though not illustrated in either example - for an object created during an interaction to continue to exist after the interaction completes(3) Rectangular boxes on the lifeline show times during the interaction when a particular object is


View Full Document

Gordon CPS 211 - Interaction

Download Interaction
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 Interaction 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 Interaction 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?