Interaction Diagrams OOAD Using the UML UseCase Analysis

  • Slides: 20
Download presentation
Interaction Diagrams OOAD Using the UML - Use-Case Analysis, v 4. 2 Copyright Ó

Interaction Diagrams OOAD Using the UML - Use-Case Analysis, v 4. 2 Copyright Ó 1998 -1999 Rational Software, all rights reserved 1/20

The Anatomy of Sequence Diagrams A Sequence Diagram describes a pattern of interaction among

The Anatomy of Sequence Diagrams A Sequence Diagram describes a pattern of interaction among objects, arranged in a chronological order; it shows the objects participating in the interaction and the messages they send. Supplier Object Client Object Sample Script : Client An object is shown as a vertical dashed line called a lifeline. Object Lifeline represents the existence of object at a particular time. An object symbol is drawn at the head of the life line. : Supplier Reflexive Message 1: Perform. Responsibility 1. 1: Perform. Another Responsibility Message Name of object & its class are separated by a colon & underlined. OOAD Using the UML - Use-Case Analysis, v 4. 2 Copyright Ó 1998 -1999 Rational Software, all rights reserved Focus of Control 2/20 Hierarchical Message Numbering

The Anatomy of Sequence Diagrams – the Message w A message is a communication

The Anatomy of Sequence Diagrams – the Message w A message is a communication between objects that conveys information with the expectation that activity will ensue. w A message is shown as a horizontal solid arrow from the lifeline of one object to the lifeline of another object. w For a reflexive message, the arrow starts and finishes on the same lifeline. w The arrow is labeled with the name of the message, (and its parameters, if known). w The arrow may also be labeled with a sequence number. OOAD Using the UML - Use-Case Analysis, v 4. 2 Copyright Ó 1998 -1999 Rational Software, all rights reserved 3/20

Anatomy of Sequence Diagrams – Focus of Control w Focus of control represents the

Anatomy of Sequence Diagrams – Focus of Control w Focus of control represents the relative time that the flow of control is focused in an object, thereby representing the time an object is directing messages. w Focus of control is shown as narrow rectangles on object lifelines. w Hierarchical numbering bases all messages on a dependent message w The dependent message is the message whose focus of control the other messages originate in. § For example, message 1. 1 depends on message 1. w Scripts describe the flow of events textually. w Be certain to include the use-case text down the left margin of the sequence diagram (style!) OOAD Using the UML - Use-Case Analysis, v 4. 2 Copyright Ó 1998 -1999 Rational Software, all rights reserved 4/20

 Anatomy of Sequence Diagram w The next example shows the object interactions to

Anatomy of Sequence Diagram w The next example shows the object interactions to support the Register for Courses use case: Create a Schedule subflow. Some responsibility allocation rationale is as follows: § The Register. For. Courses. Form (boundary class) knows what data it needs to display and how to display it. It does not know where to go to get it. Hence, this is Registration. Controller’s responsibility. § Only Register. For. Courses. Form interacts with Student actor. § The Registration. Controller understands how Students and Schedules are related due to the controller’s logic. § Only the Course. Catalog. System (a boundary class) class interacts with the external legacy Course Catalog System. w Note inclusion of the actors. This is important as it explicitly models what elements communicate with the “outside world”. OOAD Using the UML - Use-Case Analysis, v 4. 2 Copyright Ó 1998 -1999 Rational Software, all rights reserved 5/20

Example: Sequence Diagram – a “richer’ example… Sequence Diagram to Create a New Schedule

Example: Sequence Diagram – a “richer’ example… Sequence Diagram to Create a New Schedule (scenario)…(from a Use Case) : Student : Register. For. Courses. Form : Registration. Controller : Course. Catalog. System : Course Catalog : Schedule : Student 1. // create schedule( ) 1. 1. // get course offerings( ) Student wishes to create a new schedule A list of the available course offerings for this semester are displayed A blank schedule is displayed for the students to select offerings 1. 1. 1. // get course offerings(for. Semester) 1. 1. // get course offerings( ) 1. 2. // display course offerings( ) 1. 3. // display blank schedule( ) What kinds of classes are each of these? ? ? Know this. 2. // select four primary and two alternate offerings( ) 2. 1. // create schedule with offerings( ) 2. 1. 1. // create with offerings( ) 2. 1. 2. // add schedule(Schedule) At this, point the Submit Schedule subflow is executed. Note requests for service from Actor! (ahead) OOAD Using the UML - Use-Case Analysis, v 4. 2 Copyright Ó 1998 -1999 Rational Software, all rights reserved 6/20

Continuing…(two slides forward…) w Next: interaction diagram for Submit Schedule subflow. § It describes

Continuing…(two slides forward…) w Next: interaction diagram for Submit Schedule subflow. § It describes what occurs when a Student requests an entered schedule be actually submitted via the interface. § When a Schedule is submitted, an attempt is made to register the student for all selected primary courses one at a time (think: loop), as you will see in the sequence diagram. w Note the allocation of responsibility. § The Schedule has been given the responsibility for performing all of the processing associated with submitting a Schedule. (shown ahead in Sequence Diagram) • Note the complexity of the entity class! (Normal). § Schedule orchestrates a series of checks (pre-requisites, courses still open, and schedule conflicts), prior to enrolling the Student in the Course Offering. . These methods (responsibilities) must be available in all Schedule object OOAD Using the UML - Use-Case Analysis, v 4. 2 Copyright Ó 1998 -1999 Rational Software, all rights reserved 7/20

Continuing – adding a new class…(next slide) w Note: addition of new class, Primary.

Continuing – adding a new class…(next slide) w Note: addition of new class, Primary. Schedule. Offering. Info. w This class was needed to maintain the status of each particular Course Offering on a Schedule (as well as the associated grade – grade was added later). w This was added to assist in locking in courses. Responsibilities were not germane to an existing class, so this one was created to help. § This is a great potential of sequence diagrams – when they are created, some responsibilities may be noticeably missing and thus some classes may need to be created. § This is one of many reasons why we undertake sequence diagrams: to ensure all needed responsibilities are identified and assigned to objects. OOAD Using the UML - Use-Case Analysis, v 4. 2 Copyright Ó 1998 -1999 Rational Software, all rights reserved 8/20

Example: Sequence Diagram (cont. ) : Register. For. Courses. Form : Registration. Controller :

Example: Sequence Diagram (cont. ) : Register. For. Courses. Form : Registration. Controller : Schedule : Student : Primary. Schedule. Offering. Info : Course. Offering : Student Now actor wishes to submit the schedule… This sequence diagram is for Submit Schedule 1. // submit schedule( ) 1. 1. 1. // save( ) 1. 1. 2. // submit( ) 1. 1. 2. 1. // is selected? ( ) Note the loop in the Sequence Diagram… [ is selected ] 1. 1. 2. 2. // has pre-requisites(Course. Offering) Repeat for all primary course offerings. An attempt is made to register the student for all selected course Offerings one at a time!!! (See loop) 1. 1. 2. 3. // still open? ( ) 1. 1. 2. 4. // any conflicts? ( ) [ has pre-requisites, course offering open, and no schedule conflicts ] 1. 1. 2. 5. // add student(Schedule) 1. 1. 2. 6. // mark as enrolled in( ) OOAD Using the UML - Use-Case Analysis, v 4. 2 Copyright Ó 1998 -1999 Rational Software, all rights reserved 9/20

Anatomy of Collaboration (Communications) Diagrams Client Object A collaboration diagram (communications diagram) describes a

Anatomy of Collaboration (Communications) Diagrams Client Object A collaboration diagram (communications diagram) describes a pattern of interaction among objects. It shows objects participating in the interaction by their links to each other and the messages that they send to each other. Link Supplier Object : Client 1: Perform. Responsibility : Supplier (An object is represented in three ways: Message Objectname: Classname, Objectname, and : Classname) A link is a relationship among objects across which messages can be sent. In a collaboration diagram, a link is shown as a solid line between two objects. A link can be an instance of an association, or it can be anonymous – meaning that its association is unspecified. OOAD Using the UML - Use-Case Analysis, v 4. 2 Copyright Ó 1998 -1999 Rational Software, all rights reserved 10/20

Anatomy of Collaboration / Communications Diagrams - more w A message is a communication

Anatomy of Collaboration / Communications Diagrams - more w A message is a communication between objects that conveys information with the expectation that activity will ensue. (back one to slide) w In collaboration diagrams, a message is shown as a labeled arrow placed near a link. § This means that the link is used to transport, or otherwise implement the delivery of the message to the target object. w The arrow points along the link in the direction of the target object (the one that receives the message). w The arrow is labeled with the name of the message, and its parameters (no parameters shown here). OOAD Using the UML - Use-Case Analysis, v 4. 2 Copyright Ó 1998 -1999 Rational Software, all rights reserved 11/20

The Anatomy of Collaboration Diagrams more w The arrow may also be labeled with

The Anatomy of Collaboration Diagrams more w The arrow may also be labeled with a sequence number to show the sequence of the message in the overall interaction. w Sequence numbers are often used in collaboration diagrams, because they are the only way of describing the relative sequencing of messages. w (A message can be unassigned, meaning that its name is a temporary string that describes the overall meaning of the message, like //get_schedule(). You can later assign the message by specifying the operation of the message's destination object. § The specified operation will then replace the name of the message. § Frequently locked in upon further analysis) OOAD Using the UML - Use-Case Analysis, v 4. 2 Copyright Ó 1998 -1999 Rational Software, all rights reserved 12/20

Example: Collaboration Diagram Collaboration of objects to support the Register for Courses use case:

Example: Collaboration Diagram Collaboration of objects to support the Register for Courses use case: Create a Schedule subflow. It is the “collaboration diagram equivalent” of the sequence diagram shown earlier. 1. 2. // display course offerings( ) 1. 3. // display blank schedule( ) Can succinctly see messages object sends Inputs to objects neatly summarize responsibilities: in this context 1. // create schedule( ) 2. // select four primary and two alternate offerings( ) : Register. For. Courses. Form : Course Catalog : Student 1. 1. // get course offerings( ) 2. 1. // create schedule with offerings( ) : Registration. Controller 1. 1. // get course offerings( ) 1. 1. 1. // get course offerings(for. Semester) : Course. Catalog. System 2. 1. 1. // create with offerings( ) 2. 1. 2. // add schedule(Schedule) : Schedule : Student OOAD Using the UML - Use-Case Analysis, v 4. 2 Copyright Ó 1998 -1999 Rational Software, all rights reserved See messages object sends and receives in context of this subflow. 13/20

Example: Collaboration Diagram (first subflow) Collaboration of objects for Register for Courses use case,

Example: Collaboration Diagram (first subflow) Collaboration of objects for Register for Courses use case, Submit Schedule subflow. It is the “collaboration diagram equivalent” of the sequence diagram shown earlier. Note all the responsibilities of Schedule objects… Note also the associations with other objects. 1. // submit schedule( ) : Register. For. Courses. Form 1. 1. 2. 4. // any conflicts? ( ) : Student 1. 1. // submit schedule( ) 1. 1. 2. 3. // still open? ( ) 1. 1. 2. 5. // add student(Schedule) 1. 1. 1. // save( ) 1. 1. 2. // submit( ) : Registration. Controller : Schedule 1. 1. 2. 1. // is selected? ( ) 1. 1. 2. 6. // mark as enrolled in( ) : Course. Offering 1. 1. 2. 2. // has pre-requisites(Course. Offering) : Primary. Schedule. Offering. Info : Student OOAD Using the UML - Use-Case Analysis, v 4. 2 Copyright Ó 1998 -1999 Rational Software, all rights reserved 14/20

One Interaction Diagram Not Good Enough w Model ‘must ensure via the flows of

One Interaction Diagram Not Good Enough w Model ‘must ensure via the flows of events’ that all requirements needed are accommodated by the participating classes. w Start with describing the basic flow, which is the most common or most important flow of events. w Then describe variants such as exceptional flows. § You do not have to describe all the flows of events, as long as you employ and exemplify all operations of the participating objects; that is, include methods. . . § Trivial flows can be omitted, such as those that concern only one object. OOAD Using the UML - Use-Case Analysis, v 4. 2 Copyright Ó 1998 -1999 Rational Software, all rights reserved 15/20

Exception Flows w Examples of exceptional flows: § Error handling. What should system do

Exception Flows w Examples of exceptional flows: § Error handling. What should system do if error occurs? § Time-out handling. If the user does not reply within a certain period, the use case should take special measures § Handling of erroneous input to the objects that participate in the use case (e. g. , incorrect user input) w Examples of optional (alternative) flows: • The actor decides - from a number of options - what the system is to do next • The subsequent flow of events depends on the value of stored attributes or relationships • The subsequent flow of events depends on the type of data to be processed w Can use either collaboration and sequence diagrams. OOAD Using the UML - Use-Case Analysis, v 4. 2 Copyright Ó 1998 -1999 Rational Software, all rights reserved 16/20

One Interaction Diagram Not Good Enough Basic Flow Alternate Flow 1 Alternate Flow 2

One Interaction Diagram Not Good Enough Basic Flow Alternate Flow 1 Alternate Flow 2 Alternate Flow 3 Alternate Flow 4 Alternate Flow 5 Alternate Flow n AF 3 AF 1 AF 2 Note: Alternative paths return to main flow or else terminate. Must be explicit! Can all be shown visually with an Activity Diagram for that Use Case OOAD Using the UML - Use-Case Analysis, v 4. 2 Copyright Ó 1998 -1999 Rational Software, all rights reserved 17/20

Collaboration Diagrams Vs Sequence Diagrams Same information expressed in different ways… w Collaboration Diagrams

Collaboration Diagrams Vs Sequence Diagrams Same information expressed in different ways… w Collaboration Diagrams w Sequence Diagrams § Show relationships in addition to interactions § Show the explicit sequence of messages § Better for visualizing patterns of collaboration § Better for visualizing all of the effects on a given object § Easier to use for brainstorming sessions OOAD Using the UML - Use-Case Analysis, v 4. 2 Copyright Ó 1998 -1999 Rational Software, all rights reserved 18/20 § Better for visualizing overall flow § Better for real-time specifications and for complex scenarios

More on Collaboration Diagrams w Collaboration diagrams § emphasize the structural collaboration of a

More on Collaboration Diagrams w Collaboration diagrams § emphasize the structural collaboration of a ‘society’ of objects and § provide a clearer picture of the patterns of relationships and control that exist among the objects participating in a use case. w Collaboration diagrams show more structural information (i. e. , the relationships among objects). § Readily see sum of messages coming in and messages being sent from each object in toto. w Collaboration diagrams § better for understanding all the effects on a given object and for procedural design. (your logic is there!!) OOAD Using the UML - Use-Case Analysis, v 4. 2 Copyright Ó 1998 -1999 Rational Software, all rights reserved 19/20

More on Sequence Diagrams w Sequence diagrams § show the explicit sequence of messages

More on Sequence Diagrams w Sequence diagrams § show the explicit sequence of messages and § are better for real-time specifications and for complex scenarios. w A sequence diagram includes chronological sequences, but does not include object relationships. w Sequence numbers are often omitted in sequence diagrams, in which the physical location of the arrow shows the relative sequence. w On sequence diagrams, the time dimension is easier to read, the operations and parameters are easier to present, and the larger number of objects are easier to manage than in collaboration diagrams. 20/20 OOAD Using the UML - Use-Case Analysis, v 4. 2 Copyright Ó 1998 -1999 Rational Software, all rights reserved