Вы находитесь на странице: 1из 12

21/05/13

UML with Eclipse Tutorial

vogella.com

Tutorials

Training

Books

Contact us

116

UML with Eclipse Tutorial


Lars Vogel
Version 1.1 Copyright 2008 - 2009 Lars Vogel 28.12.2009
Revision History Revision 0.1 - 0.3 017.12.2007 Lars Vogel Lars Vogel Created

Free tutorial, donate to support

Training Books
bug fixes and enhancements

by Lars Vogel

Revision 0.4 - 1.1

09.10.2008

UML with Eclipse and the UM2Tools This article gives a short overview of UML2 and explains the usage of the Eclipse UML2 Tools for modeling UML 2 diagrams. This article is based on Eclipse 3.5.

Table of Contents
1. UML 1.1. Overview 1.2. Definition 1.3. UML Profiles 2. Installation of Eclipse UML2 Tools 3. Eclipse UML2 Tools 3.1. Creating UML Diagrams 3.2. Multiplicity 3.3. Interfaces 3.4. Viewing the .uml file 4. Appendix: Class diagrams 4.1. Overview 4.2. Classes 4.3. Attributes 4.4. Interfaces 4.5. Relationships 4.6. Export your class diagram as image 5. Appendix: Model-Driven Architecture (MDA) 5.1. Overview 5.2. Platform Independent Model (PIM) 5.3. Platform Specific Model (PSM) 5.4. Code Mode 6. Thank you 7. Questions and Discussion 8. Links and Literature

1. UML
www.vogella.com/articles/UML/article.html 1/12

21/05/13

UML with Eclipse Tutorial

1.1. Overview
Eclipse supports the creation of UML2 diagrams via UML2 Tools project. UML2 Tools is a set of GMFbased editors for viewing and editing UML models.

1.2. Definition
The Unified Modeling Language (UML) is a visual language for capturing software designs and patterns. The first version of UML was defined 1994 and released by the Object Management Group (OMG) in 1997 as UML v.1.1. The syntax and a semantic of UML is defined by the OMG. The basic building block for UML is a diagram. UML divides diagrams into structural diagrams and behavioral diagrams The latest version UML 2 has the target to add the ability for modelers to capture more system behavior. UML 2 has the target to support model driving architectures (MDA). MDA has the target to create automatically a software program from several models.

1.3. UML Profiles


UML is intended to be extended. The formal way to extending a UML model is via a UML profile. A UML profile a collection of UML stereotypes and constraints on elements that map the generic UML to a specific problem domain or implementation. For example a UML profile can be used to support the modeling of J2EE software components.

2. Installation of Eclipse UML2 Tools


Install the following plug-in UML2 Tools SDK The UML2 Tools can be found under "Modeling" in the update manager. Install the plugins via the update manager of eclipse (please see Using the update manager of Eclipse for details).

3. Eclipse UML2 Tools


3.1. Creating UML Diagrams
The following example will create a class diagram with the UML2 tools. Create a new java project "de.vogella.uml2.first" and a new folder "uml2". Right-click on the folder "uml2", select New-> Other. Select UML 2.1 Diagrams and then the "class diagram" as the type. In my example I will create a class diagram.

www.vogella.com/articles/UML/article.html

2/12

21/05/13

UML with Eclipse Tutorial

Define the name of you diagram as "myclasses.umlclass".

Press finish. From the "Palette" you can now select the type of element you would like to create. For example Select "Class" and click in the whitespace to create the UML representation of a class.

www.vogella.com/articles/UML/article.html

3/12

21/05/13

UML with Eclipse Tutorial

The result should look like the following.

The properties view allow you to change the attributes of the elements. To open the properties view select a class, right-click and select "Show Properties View". You can then for example set the "Is Abstract" flag to true to create a abstract class. If you select your element a menu will be displayed which allows you to add property (fields) and operations (methods).

If you select your UML diagram and click on the outgoing arrow you can create associations.

Tip

www.vogella.com/articles/UML/article.html

4/12

21/05/13

UML with Eclipse Tutorial

You can edit the properties and the operations names directly in the diagram. According to the UML specification the name of an operation should be followed by round brackets, e.g. you can type foo() but not foo for a operation.

Save your UML diagram.

Tip
Note that your UML diagram updates the *.uml file. In case you deleted your diagram you can re-create the diagram from the .uml file, via the right-click and by selecting the "Initialize * class diagram" entry in the menu.

3.2. Multiplicity
You can maintain the relationship multiplicity between two classes by clicking on the association and via the properties lower / upper in the property view.

www.vogella.com/articles/UML/article.html

5/12

21/05/13

UML with Eclipse Tutorial

3.3. Interfaces
UML2 Tool let you choose if you want to use the ball-and-socket notation (interface is displayed as a circle) or UML stereotype <<interface>> for the representation of an interface. Simple right-click on the interface and select "Show as class" of "Collapse to circle".

3.4. Viewing the .uml file


Investigate the *.uml file. The *.uml file is EMF based. Eclipse UML provides an editor for it. Alternative you can view the file directly in a text editor.

www.vogella.com/articles/UML/article.html

6/12

21/05/13

UML with Eclipse Tutorial

4. Appendix: Class diagrams


4.1. Overview
A class diagram captures the static relationships of your software.

4.2. Classes
A class is represented by a retangular box divided into compartments. A Compartment is an area in the box to write information. The first compartment holds the name, the second holds the attributes and the third is used for the operations.

Any compartment can be hidden to improve readability of the diagram. UML suggests that a class name: Starts with a capital letter is centered in the top compartment is written in a boldface font is written in italics if the class is abstract

4.3. Attributes
Attributes specifies details of a class and can be simple types or objects. Attributes can be defined inlined (as part second compartment of the diagram of the class) or as relationship. 4.3.1. Inlined Attributes Inlined attributes are placed in the second compartment of the class. The notation for inline attribute is:

visibility name: type {multiplicity} {=default}


Table 1.
Element Values Description

www.vogella.com/articles/UML/article.html

7/12

21/05/13
visibility + # ~ name type multiplicity default myName

UML with Eclipse Tutorial


public Attribute private Attribute protected Attribute package Attribute Name of the attribute following the camelCase notation Class name, interface or primitive types, e.g. int Optional, if not specified then it is assumed to be 1, * for any value, 1,..,* for ranges. Optional, default value of the attribute

4.3.2. Attributes by Relationship To model attributes by relationship you use an association relationship between the class which represents the attribute and the class containing the attribute.

4.3.3. Static Attributes Static attributes (attributes that are part of the class and not part of the instance of the class) are displayed via underlining the name of the relationship.

4.4. Interfaces
Interfaces are indicated via the stereotype <<interface>> .

Relationships can be expressed via the ball-and-socket notation.

www.vogella.com/articles/UML/article.html

8/12

21/05/13

UML with Eclipse Tutorial

4.5. Relationships
UML defines several ways of representing relationships between classes. 4.5.1. Association Read as "..has a.." association between classes. Drawn as a straight line between the two classes. Does not mean that the classes are owned by one, other classes may use the connected class too.

4.5.2. Aggregation Read as "..owns a ..". Not as strong as a composite.

4.5.3. Composition Strong relationship between classes to the point of containment. Read as "..is part of..". If the owning instance is destroyed then normally (not necessarily) the linked object is destroyed too.

www.vogella.com/articles/UML/article.html

9/12

21/05/13

UML with Eclipse Tutorial

4.5.4. Generalisation Read as ".. is a..". Use to express inheritance. Represented by a solid line and a hollow triangular arrow. For example the following code could be expressed with the following diagram.
p a c k a g ea n i m a l s ; p u b l i ca b s t r a c tc l a s sA n i m a l{ }

p a c k a g ea n i m a l s ; p u b l i cc l a s sF r o ge x t e n d sA n i m a l{ }

4.6. Export your class diagram as image


To export your diagram as image / graphic, right-click on your diagram and select File -> Save as Image File.

www.vogella.com/articles/UML/article.html

10/12

21/05/13

UML with Eclipse Tutorial

5. Appendix: Model-Driven Architecture (MDA)


5.1. Overview
MDA is the approach in which models are automatically translated into complete, deployable, running applications. MDA defines several levels for these models, Platform independent models, platform specific models and code models.

5.2. Platform Independent Model (PIM)


Represents the business model to be implemented and can be described via UML. The PIM describes the processes of the business model and the structure of the system. The PIM does not specific operating system, programming language and hardware.

5.3. Platform Specific Model (PSM)


The PSM is responsible to specify the technical details to implement the PIM, e.g. the operating system, the programming language. In case several realizations / implementations for a PIM are possible then several PSM are formulated.

5.4. Code Mode


Represents the deployable code. In an ideal MDA scenario this code could be directly compiled and deployed without human interaction.

6. Thank you
Please help me to support this article:

7. Questions and Discussion

www.vogella.com/articles/UML/article.html

11/12

21/05/13

UML with Eclipse Tutorial

Before posting questions, please see the vogella FAQ. If you have questions or find an error in this article please use the www.vogella.com Google Group. I have created a short list how to create good questions which might also help you.

8. Links and Literature


www.omg.org/uml Home of the standard body for UML http://wiki.eclipse.org/MDT-UML2Tools Wiki about the UML2 Tool project http://www.eclipse.org/modeling/ Eclipse Modeling Project

www.vogella.com/articles/UML/article.html

12/12

Вам также может понравиться