UML: Creating Collaboration Diagrams
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.
Contributed and maintained by Cindy Castillo, Bob May
November 2007 [Revision number: V1-3]
This publication is applicable to NetBeans IDE 6.0 release
Expected duration: 30 minutes
Before you proceed, make sure you review the requirements in this section.
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:
- NetBeans IDE 6.0
Select the All Download option.
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:
- Describe a specific scenario by depicting the movement of messages between the objects
- Show a spatial organization of objects and their interactions, rather than the sequence of the interactions
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:
To Generate a Collaboration Diagram
- If necessary, start the IDE.
- In the Projects window, expand the UMLTutorialProject > Model node.
- Select the following Class nodes:
Note: You can select multiple classes by pressing the CTRL key and clicking each class node.
- 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.
- In the Diagram Type list, select Collaboration Diagram.
- In the Diagram Name field, type CollaborationDiagram.
- 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
To Refine a Generated Diagram
- Click and drag the elements to rearrange the diagram to resemble the following figure.
- In the Projects window, select the Class node labeled User.
- Drag the selected class onto the Diagram editor and place it above the ATM Lifeline element as shown in the following figure.
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.
- From the Basic section of the Modeling Palette, select the Connector icon .
- Click the Lifeline element labeled User and then click ATM.
A connector link is drawn between the two elements.
- 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.
- ATM to Consortium
- Consortium to Branch
- ATM to Branch
The diagram should now resemble the following figure.
- Deselect the Connector icon by right-clicking anywhere in the Diagram editor.
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:
- Right-click in the background of the CollaborationDiagram Diagram editor.
- 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.
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.
- In the Diagram editor, select the Connector link between User and ATM.
- Right-click the portion of the Connector link closest to the ATM Lifeline.
- 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 to see the entire diagram in the Diagram editor.
- Select the Connector link between ATM and Consortium, right-click the link close to the Consortium element.
- 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.
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.
- Right-click the Connector link between Consortium and Branch, close to the Branch Lifeline element.
- Choose Operations > Add Operation from the pop-up menu.
The label appears in the diagram with the word Unnamed highlighted.
- Type verifyCardWithBank.
- Use the right arrow to move the cursor to the operation parameter field.
- 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.
- On the Connector link between ATM and Branch, right-click close to the Branch Lifeline.
- 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.
Saving Your Diagram
After you have completed your Collaboration diagram, you can save it.
- In the Diagram editor, right-click on the CollaborationDiagram tab.
- 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.
In this tutorial, you learned to create a Collaboration diagram using an existing Class diagram. You learned how to perform the following tasks:
- Generate a Collaboration diagram
- Add Connector links to the diagram
- Show message numbers on the diagram
- Show and label operation flows
- Add operations to existing links on the diagram
- Save the diagram
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.
To send comments and suggestions, obtain support, and stay informed of the latest
changes to the NetBeans IDE J2EE development features, join the firstname.lastname@example.org
>> More NetBeans IDE Documentation