Using MyEclipse: UML


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

Back to Software Engineering Tutorials



0.0 Outline
1.0 Background/Installation
2.0 Registering MyEclipse
3.0 MyEclipse Perspectives
4.0 UML with MyEclipse
5.0 Exercises
6.0 Resources

1.0 Background/Installation

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 class diagrams in Eclipse UML.

MyEclipse is an application configuration for Eclipse which extends the functionality of the IDE immensley. Its features include complete support for developing web applications and UML modeling.

IMPORTANT:

It is recommended that users of this tutorial have a moderate understanding of the basics of the Eclipse development environment. If you do not know Eclipse basics, we recommend you read The Eclipse Tutorial also located on this website.

Installing MyEclipse

In order to install and use MyEclipse, you must have Eclipse preinstalled. You can download a trial copy of MyEclipse from their website or if you are an North Carolina State student, simply check the MyEclipse option in the web installer for your course.

Class Diagrams

Each class in a Class Diagram is represented by a box with the class name, attributes, and methods (or operations). Relationships between the classes are how the classes communicate with each other. A solid line represents an association, which is a property of a class. Associations are used to represent relationships between objects (when one object has an instance of another object) while attributes show smaller things like Strings, ints, booleans, that are properties of an object.

Dependencies are when the change of one class will affect the second class. The second class depends on the first class. Some examples of dependencies are when one class calls another classes method, a class is passed in as a parameter to a method, or if a class has another class as a variable.

Aggregation and Composition are special cases of Association. Aggregation is used with a whole-part relationship. Composition is a strong form of aggregation where an instance of the part is only associated with and instance of the whole, and the part lives or dies based on the whole. But another instance of the part may be aggregated with another type of whole.

Generalization is the combining of similar traits of two similar concepts into one class and then storing the differences in subclasses. The subclass must contain (i.e. inherit) all of the elements of the superclass, but may override some of the inherited methods and/or fields. Realization indicates the implementation of some interfaces.

For more detailed information about Class Diagrams, check out Chapters 3 and 5 in Martin Fowler's UML Distilled.

This tutorial is an introduction to creating, generating code from, and reverse engineering class diagrams.

Top | Contents

2.0 Registering MyEclipse

MyEclipse is shareware which will expire in 30 days. If you have been provided a registration number as part of a course or for a company, read on in this section for the steps to register your copy. If you do not have a registration number, skip this step.

To register MyEclipse, you will need both a Subscriber ID and a Subscription Code. After opening your copy of MyEclipse, within any perspective, go to the "MyEclipse menu" and select "Update Subscription..." as demonstrated in figure 2.1.


Figure 2.1: Subscribing to MyEclipse

A dialog box will appear asking for your Subscription's ID and Code. Enter these and click "Okay." Your copy of MyEclipse is now registered.

Top | Contents

3.0 MyEclipse Perspectives

The perspective MyEclipse has to offer in which we are most interested is the UML perspective. The steps below will show you how to load this perspective in your workspace. The other perspectives can be quite useful, however, especially when developing a web application. To switch to the UML perspective, go to the icon next to the Java perspective in Eclipse and select the "MyEclipse UML" from the dropdown menu as shown in figure 3.1.


Figure 3.1: Loading the UML Perspective

Here is a quick list and description of the other perspectives MyEclipse has to offer:

  • Database Explorer: After it is configured properly, this perspective allows you to view the status, structure and data contained within your databases. This is to avoid having to write code which shows you the contents of your entire database.
  • Image Editor: Just like any other image editor, except you can edit the images contained within your projects, do image mapping and manipulate image behavior based on Java events.
  • J2EE Development: Allowing views of the current status of your system on any web development platform, this perspective automates deployment of your project to the server, and allows you to manage and configure the server.
  • Web 2.0: This perspective allows live editing of JSP and AJAX, two web interface technologies that are on the cutting-edge of the web world.
Top | Contents

4.0 UML with MyEclipse

MyEclipse makes synchronization of your code with a UML repository a snap. Before continuing through the various steps, you should make a decision as to whether you would like to create a possible design for your project before writing any code and then have MyEclipse generate the skeleton classes (Forward Engineering) or use code that you have already written to generate design diagrams either for documentation or communication (Reverse Engineering).

Sections 4.2-4.3 demonstrate how to generate diagrams using the UML perspective and then use them as a source to generate your Java basecode. Section 4.4 shows you how to reverse engineer your Java code into a diagram. Section 4.5 demonstrates how to take the diagrams within your project and export them as images for ease of use.

4.1 Creating a UML Repository

In MyEclipse, all UML must be contained within a repository. For different versions of a program or different levels of collaboration and development, one could have different repositories. Resositories are one file in MyEclipse, but they are still not source code or libraries, so we recommend placing them in a folder called /doc. To create a UML repository, go to File -> New... and select UML Model Repository from the dropdown menu that appears as in figure 4.1.


Figure 4.1: Creating a UML Repository

A dialog box will appear asking you which folder you would like to create the repository within, select your documentation folder or any folder that is not a source folder and click "Okay". Your repository will load within the perspective.

4.2 Creating a class diagram

After you have completed section 4.1 or already have a UML repository, you can create UML diagrams using the MyEclipse editor. When your repository is showing within the MyEclipse UML perspective, you should see a toolbar that looks like figure 4.2a.


Figure 4.2a: Creating a new diagram

Hover your mouse over each button to see which type of class it creates. The classs types from left to right in figure 4.2a are class, use case, sequence, activity, state, collaboration and deployment.

Now is a good time to discuss the properties view. When you load any diagram within the MyEclipse UML perspective, the properties view will appear at the bottom of your screen (see figure 4.2b).


Figure 4.2b: The Properties

This editor will allow you to manipulate the various facets of any object within your UML repository. From the repository itself all the way to an element within an action that is a trigger of a transition of a state that is within a state diagram... you get the idea. Proper use of the properties view requires a knowledge of UML and Java.

Upon creating a diagram, you should also see a set of buttons for each type. The following figure shows the buttons for class diagrams (figure 4.2c). Hover your mouse over each to see what type of element it allows you to create.


Figure 4.2c: Class Diagram buttons

To create each element, click the button and click within the diagram where you would like the place the element. It will appear as an "anon" element until you edit its properties (see figure 4.2b).

4.3 Forward Engineering

In some situations, you will have the ability to design your project before you write a line of code. After you have created a class diagram to demonstrate the relationships within your project, you can forward engineer this UML into skeleton code: the code for a class with nothing in it.

The first step in doing this is of course to have a class diagram predrawn. If you have a class diagram that suits your needs, and are in the MyEclipse UML perspective, click the "UML" menu and select "Generate Java..." as in figure 4.3a.


Figure 4.3a: Engineering to/from Diagram

The dialog box shown in figure 4.3b will appear, wherein you will need to declare which classes and packages you would like to create code for and where this code should be placed. It is helpful at this step to already have a source folder created. If you do, select this folder for the "output folder" and check any classes for which you would like to create Java skeleton code.


Figure 4.3b: Engineering to Java Code

4.4 Reverse Engineering

When you would like to take Java code that has already been written and generate a UML diagram of a certain detail that shows only the relationships you would like to communicate, you need to follow a process called reverse engineering. To do this within MyEclipse, you need to have prewritten Java code, a UML repository and have your UML repository open in the MyEclipse UML perspective. When you have these prerequisites, go to the UML menu and select "Reverse Engineer UML from Java..." The menu is shown in figure 4.4a but with the wrong option highlighted.


Figure 4.4a: Engineering to/from Diagram

A dialog box will appear which asks you which classes and packages you would like to show on your class diagram. Select the ones which contain the area of your project you are highlighting (possibly all) and click "Next" as shown in figure 4.4b.


Figure 4.4b: Engineering from Java Code

MyEclipse now wants to know what you want on your diagram. Your options are shown in figure 4.4c. If you check the box marked "Hide Class/Interface details," your diagram will show only the classes and their relationships. Leaving this box unchecked will reveal their methods and properties as well. The model attributes option dictates how you would like to show the "uses" stereotype. With the association option, the UML "association" line will be drawn between the two classes. With the attributes option, the used class will just be shown as a member of the class using it.


Figure 4.4c: Reverse Engineering Options

4.5 Exporting Images

Many people do not have MyEclipse and cannot open the files with which it stores UML Model Repositories (UMR). The most universal way to share UML is through an image file. This allows other developers (or perhaps your professor or TA) a brief view of the structure of your system in an easy to open format. To export your diagram as an image, you need to be in the MyEclipse UML perspective, have the diagram predrawn and have it showing. Then, right click on the image and select "Export as Image..." as shown in figure 4.5. We recommend keeping a backup copy of your UML diagrams in your /doc folder for easy publishing.


Figure 4.5: Exporting as an Image

Top | Contents

5.0 Exercises

These exercises will help you to learn how to use MyEclipse's UML perspective to model the system with the CoffeeMaker project (documentation, project files). Download the project files and import them into your workspace to begin. When you have completed the exercise, show your work to your TA for lab credit.

The Exercise

Create a class diagram of the CoffeeMaker project by reverse engineering the Java code. Create the diagram such that it shows every member of each class (methods and fields) and demonstrates the uses relationship by the UML "uses" arrow. Export the diagram as a JPEG file.

Top | Contents

6.0 Resources

  • MyEclipse Documentation
  • Download Eclipse
  • UML Resource Page
  • Top | Contents

    Back to Software Engineering Tutorials
    Installing Eclipse Plug-ins ©2006 North Carolina State University, Laurie Williams, Sarah Smith , Ben Smith
    Email Sarah Smith with any questions or comments about this tutorial.
    Last Updated: Wednesday, July 26, 2006 1:46:50 PM