Sequence Diagrams in Eclipse


Laurie Williams, Dright Ho, and Sarah Smith
CSC 326 - Software Engineering
Department of Computer Science
North Carolina State University


0.0 Outline
1.0 Background on UML, Eclipse UML, and Sequence Diagrams
2.0 Creating a Sequence Diagram
3.0 Creating Objects in a Sequence Diagram
4.0 Tips and Tricks
5.0 Exercise
6.0 Resources

1.0 Background on UML, Eclipse UML, and Sequence Diagrams

UML

UML (Unified Modeling Language) was developed by Grady Booch, James Rumbaugh, and Ivar Jacobson, at Rational Software Corporation in 1997, for a standard way to model the structure of large applications. The UML is a standard maintained by the Object Management Group (OMG). The current version of UML is 2.0. UML provides a standardized way of modeling software, so the everyone can understand a given model. UML has several different modeling types: class diagram, sequence diagrams, state charts, and use cases to name a few. This tutorial will introduce programmers to creating sequence diagrams in Eclipse UML.

Eclipse UML

Eclipse UML is an Eclipse plug-in developed my Omondo. There is a free edition and a studio edition of Eclipse UML. The free edition will cover the modeling needs for CSC 326. You can download Eclipse UML here. After you have downloaded Eclipse UML, double click the jar file, which will then run an installer program. This will install Eclipse UML as a plug-in. We are using Eclipse UML release 2.1.0.20050718. You need to have the Eclipse Modeling Framework (EMF), Graphical Editor Framework (GEF) and UML2 Eclipse plug-ins installed. These are all Eclipse projects, and you can install them by connecting to the Eclipse update site inside of Eclipse (see Installing Plugins in Eclipse tutorial)

Sequence Diagrams

A sequence diagram is a visual representation of how objects in a system interact. These interactions are captured in a single scenario, which is a specific path of behavior in a system for a particular use case or set of use cases. A program will have many different scenarios. A sequence diagram will contain the objects that are part of the scenario and the messages that are passed between the objects or participants of the scenario.

An object or participant is represented by a box with a dashed line vertically out the bottom of the box. The line represents the lifeline of the object. When an object is active (a method is running) a rectangle is on the lifeline. Messages are represented as dark triangle arrows. An object can send a message to another object by calling the second object's method. An object can also send a message to itself by calling one of its own methods. Returns from a method are represented by a dashed arrow.

Objects may create or delete other objects during the first object's lifeline. Loops, conditionals, etc may also be represented in a sequence diagram.

Top | Contents

2.0 Creating a Sequence Diagram

Like class diagrams, sequence diagrams in Eclipse UML can be tied to a project's source code, but creating new components in a sequence diagram will not change your program. If you have already started writing a program, you can select objects in your program as part of the sequence diagram and you can select methods from those objects as part of the messages that are passed between objects. If you start by creating a sequence diagram, code will not be generated.

The sequence diagram file is stored in the source directory or package of the associated source code. You can also create sequence diagrams in another folder of the project.

2.1 There are three ways to create a sequence diagram:

2.1.1 Select File > New > Other... > UML Diagrams > Sequence Diagrams ,

2.1.2 Select the arrow of the button in the upper left of the toolbar. Select Other... > UML Diagrams > Sequence Diagrams, or

2.1.3 Right click on the source folder of package that you want to create a sequence diagram in and select New > Other... > UML Diagrams > Sequence Diagrams.

2.2 Press Next. Give the sequence diagram a file name. All sequence diagrams end in a .usd extension.

Top | Contents
3.0 Creating Objects in a Sequence Diagram

Below is the sequence diagram tool bar. This is displayed at the top of the Sequence Diagram editor window. A discussion of each of the tools is also below.

  • : Selects a component of a sequence diagram
  • : Zooms in on the sequence diagram
  • : Creates an object and its lifeline
  • : Creates an actor that interacts with objects in a sequence diagram
  • : Creates a message between two objects
  • : Creates a self message on an object
  • : Creates a control structure like a for loop or conditional
  • : Creates an indication
  • : Creates a note
  • : Creates a link
  • : Creates a label

To add one of these components to a diagram, select the component and drag the curser from a starting point to an ending point in the editor. When you are creating an object or actor, you will need to drag a rectangle of the size you want the object or actor to be in the diagram. The connector icons will need to be dragged from a source object to a destination object.

Associating Components of a Sequence Diagram with Source Code

When you create an object, you can specify the type of object that you want to create. This type can be any of the classes and interfaces on the classpath of your project including files in your project. When you have created objects with an associated type, you can then select the methods that are called to send messages when creating a message between two object or when creating a self message.

Top | Contents
4.0 Tips and Tricks

4.1 If you wish to see more of your sequence diagram you can zoom out using the zoom feature located in the toolbar.

Top | Contents
5.0 Exercise

Import the CoffeeMaker project into your workspace. Create a sequence diagram in the models folder for the following scenario:

A student creates a new recipe Hot Chocolate with a price of $.50, 0 units of coffee, 1 unit of milk, 2 units of sugar, and 3 units of chocolate. Next, the student purchases a hot chocolate from the CoffeeMaker, and receives change of $.20.

Show your sequence diagram to your TA for credit.

Top | Contents
6.0 Resources
Top | Contents


Sequence Diagrams in Eclipse Tutorial ©2003-2005 North Carolina State University, Laurie Williams, Dright Ho, Sarah Smith
Email Sarah Smith with any questions or comments about this tutorial.
Last Updated: Tuesday, September 20, 2005 2:57 PM