
UML - Quick Tutorial
We assume the user is familiar with UML diagrams. The following is a quick
tutorial on using UML in a project. After installing the EMF-UML plugin, exit
Eclipse and reinvoke it.
- Create a Java project using Eclipse.
- Choose File | new | other from the menu. Then
choose UML Diagrams in the left panel of the popup window and UML class diagram
in the right panel. Click Next.
- In the next page, you should see a file name, (default diagram).ucd, listed.
You can rename this to myuml.ucd or whatever. Be sure to include the .ucd
extension. Click Finish.
At this point you can create UML diagrams in the editor. Here's a short example:
- Click on the "Create a class" button in the editor (or right click
inside the editor and choose new | class from the popup
menu). Provide a class name, like Foo, and check the class properties (public,
etc.) you want. If the class is to contain main(), be sure to check the box
public static void main(String[] args). You do not need
to provide a package name or enter other information unless you need to for
your project. Click Finish.
- An rectangular class diagram is then displayed in the editor. If you right
click on the diagram and choose new, you can add methods (functions)
and attributes (member variables) to the class. For example, add an attribute,
age. Choose int for its type. Leave the other default settings.
When you click OK, two function names are displayed in the class diagram,
getAge() and setAge(). Since the attribute was defined private, you
will not see age displayed in the class diagram. By double clicking the diagram,
a source code editor appears with the code for Foo. You can also right click
on a diagram and choose View selector from the popup menu. From here
you can define what is visible within the class diagram. For example, private
attributes can be made visible within the class diagram.
- As you add more classes and edit existing ones, the UML engine creates/edits
the Java code.
This tutorial just scratches the surface of the UML capabilities. Use the help
menu for details on using UML. Ignore the EMF part of the plugin as it is an
advanced tool for creating complex applications. See the getting started
section of the EclipseUML plugin user guide (in the help page) for details on
associations and inheritance.
You can also create a UML file for an existing Java project. Once defined,
just drag and drop existing java source files onto the UML editor to create
a class diagram. If you prefer to view private methods and attributes, right
click on the class diagrams to invoke the View selector and choose
what is to be viewed. Any packages defined within the project are also imported
into the UML editor.