UML With Eclipse Tutorial

Embed Size (px)

Citation preview

  • 7/30/2019 UML With Eclipse Tutorial

    1/12

    21/05/13 UML with Eclipse Tutorial

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

    116

    Free tutorial, donate

    to support

    by Lars Vogel

    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

    Created

    Revision 0.4 - 1.1 09.10.2008 Lars

    Vogel

    bug fixes and enhancements

    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. Ov erview

    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. Ov erview

    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

    vogella.com Tutor ia ls Tra ining Books Contact us

    http://www.vogella.com/articles/UML/article.html#mda_overview_s1s2chttp://www.vogella.com/contact.htmlhttp://www.vogella.com/books.htmlhttp://www.vogella.com/training/overview.htmlhttp://www.vogella.com/training/overview.htmlhttps://profiles.google.com/104044918586174763681http://www.twitter.com/vogellahttp://www.vogella.com/contact.htmlhttp://www.vogella.com/books.htmlhttp://www.vogella.com/training/index.htmlhttp://www.vogella.com/tutorials.htmlhttp://www.vogella.com/http://www.vogella.com/articles/UML/article.html#resourceshttp://www.vogella.com/articles/UML/article.html#questionshttp://www.vogella.com/articles/UML/article.html#thankyouhttp://www.vogella.com/articles/UML/article.html#mda_overview_s1s2dhttp://www.vogella.com/articles/UML/article.html#mda_overview_s1s2chttp://www.vogella.com/articles/UML/article.html#mda_overview_s1s2bhttp://www.vogella.com/articles/UML/article.html#mda_overview_s1s2ahttp://www.vogella.com/articles/UML/article.html#mda_overviewhttp://www.vogella.com/articles/UML/article.html#class_exporthttp://www.vogella.com/articles/UML/article.html#class_diagramss1s2ehttp://www.vogella.com/articles/UML/article.html#class_diagramss1s2dhttp://www.vogella.com/articles/UML/article.html#class_diagramss1s2chttp://www.vogella.com/articles/UML/article.html#class_diagramss1s2bhttp://www.vogella.com/articles/UML/article.html#class_diagramss1s2ahttp://www.vogella.com/articles/UML/article.html#classModel-Driven%20Architecture%20(MDA)%20development_diagramshttp://www.vogella.com/articles/UML/article.html#eclipseuml_filehttp://www.vogella.com/articles/UML/article.html#umltools_interfacehttp://www.vogella.com/articles/UML/article.html#umltools_multiplicityhttp://www.vogella.com/articles/UML/article.html#umltools_diagramhttp://www.vogella.com/articles/UML/article.html#umltoolshttp://www.vogella.com/articles/UML/article.html#installhttp://www.vogella.com/articles/UML/article.html#uml_profileshttp://www.vogella.com/articles/UML/article.html#uml_definitionhttp://www.vogella.com/articles/UML/article.html#uml_overviewhttp://www.vogella.com/articles/UML/article.html#umlhttp://www.vogella.com/people/larsvogel.html
  • 7/30/2019 UML With Eclipse Tutorial

    2/12

    21/05/13 UML with Eclipse Tutorial

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

    1.1. Overview

    Eclipse supports the creation of UML2 diagrams via UML2 Tools project. UML2 Tools is a set of GMF-

    based 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 diagramsand

    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.

    http://www.vogella.com/articles/Eclipse/article.html#updatemanager
  • 7/30/2019 UML With Eclipse Tutorial

    3/12

    21/05/13 UML with Eclipse Tutorial

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

    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.

  • 7/30/2019 UML With Eclipse Tutorial

    4/12

    21/05/13 UML with Eclipse Tutorial

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

    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

  • 7/30/2019 UML With Eclipse Tutorial

    5/12

    21/05/13 UML with Eclipse Tutorial

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

    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.

  • 7/30/2019 UML With Eclipse Tutorial

    6/12

    21/05/13 UML with Eclipse Tutorial

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

    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 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.

  • 7/30/2019 UML With Eclipse Tutorial

    7/12

    21/05/13 UML with Eclipse Tutorial

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

    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 attributesand

    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 asrelationship.

    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

  • 7/30/2019 UML With Eclipse Tutorial

    8/12

    21/05/13 UML with Eclipse Tutorial

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

    visibility +

    -

    #

    ~

    public Attribute

    private Attribute

    protected Attribute

    package Attribute

    name myName Name of the att ribute fol lowing the camelCase notation

    type Class name, interface or pr imit ive types, e .g. int

    multiplicity Optional, if not specified then it is assumed to be 1, * for any value, 1,..,* for ranges.

    default Opt ional, default value of the attr ibute

    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 .

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

  • 7/30/2019 UML With Eclipse Tutorial

    9/12

    21/05/13 UML with Eclipse Tutorial

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

    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.

  • 7/30/2019 UML With Eclipse Tutorial

    10/12

    21/05/13 UML with Eclipse Tutorial

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

    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.

    package animals;publicabstractclass Animal {}

    package animals;publicclass Frog extends Animal {}

    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.

  • 7/30/2019 UML With Eclipse Tutorial

    11/12

    21/05/13 UML with Eclipse Tutorial

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

    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

    http://flattr.com/thing/49772/Tutorials-for-Eclipse-Java-Android-and-Webprogramming
  • 7/30/2019 UML With Eclipse Tutorial

    12/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

    http://www.eclipse.org/modeling/http://wiki.eclipse.org/MDT-UML2Toolshttp://www.omg.org/umlhttp://www.vogella.com/blog/2010/03/09/asking-community-questions/http://groups.google.com/group/vogellahttp://www.vogella.com/faq.html