UML: Creating Collaboration Diagrams

Contributed and maintained by Cindy Castillo, Bob May
November 2007
[Revision number: V1-3]
This publication is applicable to NetBeans IDE 6.0 release

In this tutorial, you learn how to use the UML features of the IDE to create a UML Collaboration diagram. A Collaboration Diagram is an interaction diagram that emphasizes the structural organization of the objects that send and receive messages. It is a diagram that shows interactions organized around instances and their links to each other.

Expected duration: 30 minutes

Contents

  Content on this page applies to NetBeans IDE 6.0

Tutorial Requirement

Before you proceed, make sure you review the requirements in this section.

Prerequisites

This tutorial requires that you complete the companion tutorial, UML: Creating Class Diagrams. This tutorial uses the completed Class diagram from that tutorial.

To use this tutorial, the IDE must be installed on your system and you should be familiar with the basic parts of the IDE. You should also have a basic familiarity with the Java programming language and UML. For a basic understanding of the IDE, see the IDE Basics topics in the online help. A good resource for UML techniques and theory is the official UML resource page at http://www.uml.org/

Software Needed for This Tutorial

Before you begin, download and install the following software:

top

Using Collaboration Diagrams

Collaboration diagrams let you show a spatial organization of components and interactions rather than concentrating on the sequence of the interactions. A collaboration diagram shows an interaction organized around the objects in the interaction and their links to each other. Unlike a Sequence diagram, a collaboration diagram shows the relationships among the objects. On the other hand, a collaboration diagram does not show time as a separate dimension, so sequence numbers determine the sequence of messages and the concurrent threads. A collaboration diagram is a cross between a symbol diagram and Sequence diagram, in that it describes a specific scenario by numbered arrows that show the movement of messages during the course of a scenario.

The Collaboration diagram may be used to:

top


Creating Collaboration Diagrams

This tutorial uses the Class diagram that is created in the tutorial UML: Creating Class Diagrams. You should complete the Class diagram tutorial before proceeding with these steps.

This section contains the following procedures:

top


To Generate a Collaboration Diagram

  1. If necessary, start the IDE.
  2. In the Projects window, expand the UMLTutorialProject > Model node.
  3. Select the following Class nodes:
    • ATM
    • Branch
    • Consortium
    Note: You can select multiple classes by pressing the CTRL key and clicking each class node.
  4. Right-click the last selected class and choose Create Diagram From Selected Elements from the pop-up menu.
    The New Wizard opens and displays the Create New Diagram page.
  5. In the Diagram Type list, select Collaboration Diagram.
  6. In the Diagram Name field, type CollaborationDiagram.
  7. Leave the default setting in the Namespace field and click Finish.
    The IDE does the following:
    • Creates the CollaborationDiagram node under the Model node in the Projects window
    • Displays the new diagram in the Diagram editor (the diagram consists of three classes depicted as Lifeline elements)
    • Opens the Modeling Palette

top


To Refine a Generated Diagram

  1. Click and drag the elements to rearrange the diagram to resemble the following figure.

    Collaboration Diagram with Rearranged Lifelines

  2. In the Projects window, select the Class node labeled User.
  3. Drag the selected class onto the Diagram editor and place it above the ATM Lifeline element as shown in the following figure.

    Collaboration Diagram with Added Lifeline

top


Adding Connector Links

Each element in a Collaboration diagram may be connected by Connector links to other elements. These links can be identified and have message flows added to them.

  1. From the Basic section of the Modeling Palette, select the Connector icon Actor icon is displayed..
  2. Click the Lifeline element labeled User and then click ATM.
    A connector link is drawn between the two elements.
  3. Use the same procedure to draw the following links:
    Note: When you create the link from ATM to Branch, draw the link straight out to the right from the ATM Lifeline, click once directly above the Branch Lifeline. A vertex is placed on the link line, then draw the link straight down to the Branch Lifeline.

    The diagram should now resemble the following figure.

    Collaboration Diagram With Links

  4. Deselect the Connector icon by right-clicking anywhere in the Diagram editor.

top


Showing Message Numbers

A Collaboration diagram represents a specific scenario by using numbered messages. The default UML setting hides these numbers. Use the following steps to show the message numbers:

  1. Right-click in the background of the CollaborationDiagram Diagram editor.
  2. Choose Show Message Numbers from the pop-up menu.
    When you insert the operation flows (in the next section), the message numbers appear.

    Note: The integer represents the sequential order of the message within the next higher level of procedural calling. Messages that differ by one integer are sequentially related at that level of nesting. For example, message 3.1.4 follows message 3.1.3 within activation 3.1.

top


Showing Operation Flows

An operation flow is shown on the diagram as a labeled arrow placed parallel to a link. This link is used to transport or implement the delivery of the message to the target element.

  1. In the Diagram editor, select the Connector link between User and ATM.
  2. Right-click the portion of the Connector link closest to the ATM Lifeline.
  3. Choose Operations > public float getCashOnHand from the pop-up menu.
    The operation flow is placed on the diagram and numbers it with the integer 1.

    Note: Click the Fit to Window button image of the Fit To Window icon is displayed. to see the entire diagram in the Diagram editor.
  4. Select the Connector link between ATM and Consortium, right-click the link close to the Consortium element.
  5. Choose Operations > public void validateAccountInfo from the pop-up menu.
    The IDE places the selected operation on this link and numbers it with the integer 1.1.

    Note: You can select the operation flow and move it if needed.

top


Adding Operations to a Class

In this procedure, you add a new operation to the Connector link. This operation is also added to the Branch class in the ClassDiagram diagram and to the Java source code.

  1. Right-click the Connector link between Consortium and Branch, close to the Branch Lifeline element.
  2. Choose Operations > Add Operation from the pop-up menu.
    The label appears in the diagram with the word Unnamed highlighted.
  3. Type verifyCardWithBank.
  4. Use the right arrow to move the cursor to the operation parameter field.
  5. Type int stringCardStrip for the parameter and press Enter.
    The link is labeled 1.1.1:public void verifyCardWithBank(int stringCardSTrip) and the operation appears in the Branch class in the ClassDiagram diagram.
  6. On the Connector link between ATM and Branch, right-click close to the Branch Lifeline.
  7. Choose Operations > public char getConnected from the pop-up menu.
    The link is labeled 1.2:public char getConnected().

Your finished diagram should resemble the following figure.

Completed Collaboration Diagram

top


Saving Your Diagram

After you have completed your Collaboration diagram, you can save it.

  1. In the Diagram editor, right-click on the CollaborationDiagram tab.
  2. Select Save Document from the pop-up menu.
    The menu closes and the diagram is saved.

    Note: When you exit from the IDE, you are prompted to save your project.

top


Summary

In this tutorial, you learned to create a Collaboration diagram using an existing Class diagram. You learned how to perform the following tasks:

You can create a scoped Sequence diagram directly from this Collaboration diagram. Use the tutorial UML: Creating Sequence Diagrams to learn how to do this.

top

Next Steps


Send Us Your Feedback

top

>> More NetBeans IDE Documentation

www.000webhost.com