StarUMLIntro

download StarUMLIntro

of 6

Transcript of StarUMLIntro

  • 8/10/2019 StarUMLIntro

    1/6

    Introduction to StarUML

    David Gee

    August 27, 2012

    1 Introduction

    In this short guide, well be looking at StarUML, which well be using in CM0570 for the purpose of drawing UML diagrams.We tell you how to start StarUML and how to create the types of diagram which youll meet on the module. Notice that if

    you havent come across some of these diagrams before, the terminology used might not seem to make senserest assuredthat it will once youve learnt about the diagrams themselves.

    2 Starting StarUML

    StarUML is a CASE1 tool. As such it lest you draw UML diagrams, but there is a lot more to it than that. For one thing,it keeps track of the things you create; even when something appears on more than one diagram, provided you use itcorrectly, as we shall see. It also lets you generate code from your UML diagrams in a number of languages, including Java.

    StarUML is a native Windows application. This means that it runs more quickly than some other tools, but it also meansthat you can only run it underWindows. It does, however, run quicklyenough to be usable on a version of Windows runningon a virtual machine such as Parallels Desktop or Virtual Box.

    You start StarUML from the Windows Start Menu. When you do so you will see the New Projectdialog box (figure 2). Itoffers a number of approachesthese affect the way in which the diagrams are managed in the Model Explorer part ofthe main window.

    Figure 1: New Project Dialog Box

    For now, select theRational Approach, and click OK. You will now see the main window of Star UML, as seen in figure2. Notice the contents of this windowyou will see the Toolboxat the left, theModel Explorerand Propertieswindows at theright, and in the middle, the drawing window where you create the diagrams. Initially there is a tab marked Main whichrepresents a class diagram in the Logical View.

    3 Creating Diagrams

    3.1 Class Diagrams

    Well start by looking at the Model Explorersee figure 3. The unexpanded view is shown on the left; if we expand each ofthe nodes the view changes to that shown on the right. Notice that each View has a Main item; the one we see is in theLogical View, and it is a class diagram.

    1Computer-Aided Software Engineering

    1

  • 8/10/2019 StarUMLIntro

    2/6

    Figure 2: StarUMLMain Window

    Figure 3: Model Explorer

    To populate the class diagram, we click on one of the tools in the toolboxsee figure 4. Then click at the place withinthe diagram area where we want the object to be created. An instance of thr type of object we selected will then appear atthat point on the diagramobviously you will want to change the default name (unusually, the names appear to be thoseof StarUMLs creators, used in turn).

    We can create further elements by repeating this process. In order to link elements, we simply click on one of theappropriate symbols in the toolbox, then, on the diagram, drag from the source of the association (e.g.) to the target. Wecan then select the line and view its properties in theProperties Windowat the bottom right of the screen; here we can namethe association, set the multiplicities and so on.

    Adding attributes and operations to a class is also straightforward. We right-click on the class concerned, then selectAddandAttribute. We can then type the name of the attribute to replace the offered default. Notice that we can precedethe name by a visibilty symbol, and follow it with a colon and the name of the attributes type, and these will be recognisedas such (well see what is meant by these and how the visibility and type are depicted on a UML class diagram in due course).

    Notice that as we create classes, they are shown in the Model Explorer. If we want to add the same thing (I dont want

    to use the word object, as it has a specific meaning in UML!) to more than one diagram, we can drag it on to the diagramfrom the Model Explorer. Well see an example of this when we look at creating Sequence Diagrams. See figure 5. If we addsomething by mistake, we must select it in Model Explorer and then selectDelete from modelfrom Model Explorer. If we justdelete it from the diagram, it stays in the model itselfbeware!

    2

  • 8/10/2019 StarUMLIntro

    3/6

    Figure 4: Toolbox

    3.2 Use Case Diagrams

    You should have met these last yearbut obviously you havent yet used StarUML to create such a diagram. As it happensthe process is quite straightforward, and not dissimilar from creating a class diagramalthough obviously the contents ofthe Toolbox will be different. In fact, Start UML has created an emoty use case diagram called Main for youlogicallyenough, its within the Use Case View in Model Explorer.

    Double-click on the diagrams icon within Model Explorerto show the diagram. Then click on the System Boundaryelement, and draw it at an appropriate size on the diagram by dragging the mousethe outline of the element is shown asa dashed rectangle. You can then click on other types of elements and add them.

    You can use an Association element to link an Actor with a use case; to relate use cases you can employ the Includeand Extend links in the toolbox. Remember that you need to drawfromthe extending use case tothe parent use casefor an extends relationship, andfromthe parenttothe included use case for an includes relationship.

    3.3 Sequence Diagrams

    With the Logical View selected in Model Explorer, selectAdd Diagram|Sequence Diagamfrom theModelmenu (or the right-click menu) to create the diagram. You can give it a name in Model Explorer or via its properties. The first element toaddif we want to stick to the UML 2 conventionsis a Frame. As with the System Boundary for the use case diagram,

    you can drag it out to an appropriate size on the screen (obviusly you can resize it later if you want).Once youve done this, the easiest way of populating the sequence diagram is to drag elements from Model Exploreron

    to the diagram. Dragging a class creates a lifeline for an anonymous member of that class (which is usually what you wantanyway; you can add a name via the Properties window if you wish). You can also drag Actors on to the diagram if needed(you will often need at least one).

    To add messages between objects, the Stimulus element from the toolbox is used. If you dont want to create a CALLaction (the default) you will need to change theAction Kindin Properties. Notice that, in StarUML, a CREATE action does notgo in to the side of the objects box as in most interpetatons of the UML standardbut this is fine and wont cost you anymarks in assignments! However a DESTROY action does correctly place a X at the bottom of the lifeline.

    3

  • 8/10/2019 StarUMLIntro

    4/6

    Figure 5: Model Explorer, showing Classes

    3.3.1 Combined Fragments

    These are the way in which selection and iteration are added to sequence diagrams. You add a Combined Fragment usingthe appropriate element in the toolbox. You will almost certainly need to change the interaction operatorthe defaultisseq. Just select an alternative from the drop-down list.

    You now need to set the guard for what StarUML calls the interaction operand. You doNOT use the InteractionOperand element in the toolbox for this (but see below) as one has already been createdyou just need to select it. Some-timesclicking on theCombined Fragment in thediagram achieves this, but the easiest way is simply toexpand the CombinedFragments node inModel Explorer, and select the Interaction Operand there. You can then type the guard into the appro-priate text box in Properties.

    So whatisthe Interaction Operand element in the toolbox used for, then? Its to add additionalinteraction operands to

    fragments which require more than onein other words, altfragments. Figure 6 shows an example of a simple sequencediagram created with StarUML.

    4 Generating Java Code

    Wouldnt it be nice if a tool would do morethan let us draw diagrams (and, perhaps, make sure they are correct). Well.many CASE tools will generate code from us, and StarUML is no exception. Just dont expect too muchall that can really begenerated are the outlines of classesin other words the classes themselves and their methods, as seenon the class diagram.In order to work best, youll need to set the return types of methods, and the types of parameters, using Properties.

    The return type of a method is also regarded as a parametera rather special one. To add a parameter, select themethod concerned in Properties, and Add|Parameterfrom the right-click menu. For the return type, you need to set theDirectionKind to RETURN (it defaults to IN). Any other DirectionKind is not appropriate for use with Java. By far the easiest

    way to set the return type, however, is to double-click the name of the method on the diagram, move the cursor to the endof the nameafter the closing )and type a colon followed by the name of the type, e.g. :void.

    Done this? Well, we now need to add the Java profile to our project before we can actually generate code. To do this,selectModel|Profilefrom the menu, to display the Profile Manager. Then click on Java in the left-hand box and then on theInclude> button. Now click the Close button. See figure 7.

    Then, create a directory to hold the generated code using Windows Exploreryou cant do this later. Once youve donethis, selectTools|Java|Generate Codefrom the menu. This takes you to a wizard which manages the generation process. First,

    you need to select the Starting Package Location. This should be the Logical View as shown in figure . Next, youneed to select the elements to generate code fromhere, we have selected the Lecturer classsee figure . Finally, weneed to select the directory where the code is to be generated. This will only allow you to select an existing directorywhichis why I suggested you should create an appropriate directory first.

    As for the code? Here it is!

    public class Lecturer {public void addStudent() {

    }

    }

    4

  • 8/10/2019 StarUMLIntro

    5/6

    Figure 6: Example Sequence Diagram

    Figure 7: Profile Manager

    Figure 8: Code Generation Wizard Screens

    5

  • 8/10/2019 StarUMLIntro

    6/6

    5 Summary

    Well, weve looked at how we can use StarUML to create UML diagrams and how we can also use it to generate some code inJava. Its open source so you can download a copy for your own use: http://staruml.sourceforge.net/en/download.php. ItisWindows only but its not very demanding and will run successfully under a virtual Windows running with Virtu-alBox or Parallels Desktop, for example.

    Good luck!

    6