Creating class diagrams using StarUML

Source: Internet
Author: User
Tags staruml

Creating class diagrams using StarUML

http://www.flyne.org/article/379

1. Overview (What)

STARUML is a tool for generating class diagrams and other types of UML diagrams . This article is a concise manual for creating class diagrams (Java language descriptions) using STARUML.

STARUML (SU) is a tool that creates UML class diagrams and can automatically generate Java's "stub Code". Su can also do Java reverse engineering to produce the corresponding UML diagram.

In this tutorial, we'll use SU to design a pizza pie. Follow the next steps to create a UML diagram as shown below. su can generate code that reflects the class structure, not the concrete implementation of any object . Therefore, after you create a chart using Su, you should also add the remaining functional code for this stub, filling in what each method should do.

2. Create a new "canvas"

1. Add a new project

Start StarUML, then a dialog named "New project by Approach" pops up, select "Empty Project", and you can see the new "Untitled" project in the Model Explorer panel on the right. The properties of the project can be modified (project name, author, and so on) in the property panel below.

2. Add a model

via the "model" main menu, or right-click on the project in the Model Explorer panel, then "Add-model"

3. Add Class Diagram

via the "model" main menu, or right-click the selected model, and then "Add diagram-class Diagram".

4. Set profile (UML outline)

Use the "Model-profile ..." menu to set the profile required for the project. This determines the rules and conventions used by the project . Be sure to include the "JAVA Porfile" project.

5. Save the Project

Save the project right away so you don't lose information when there's a problem.

From the File menu, select Save and select a place to save the project. Your STARUML project should now look like this:

3. Start "painting" (How)

1. Create a chart

Now, to really create the chart, choose the class icon from the Toolbox panel on the left of the screen by default, and then left-click somewhere in the Diagram window. This creates a new class using the generic name. Double-click to rename the class to circle.

2. Adding attributes

Right-click the target in the diagram, select "Attribute" in the pop-up menu (labeled Green), add an attribute (or field) to it, and fill in the desired name "_radius".

      • In the properties panel at the bottom right of the form, locate the Type input box and enter double as the _radius property.
      • The internal data (domain/attribute) of the class is private because they are strictly used internally by the class. So, in the Properties panel, set the _radius to private.

3. Continue with the design

Repeat the same procedure, adding a class named rectangle and a private member of the double type _width and _height. (The following paragraph is the use of the attention, the total sense of translation is not very good, the original text moved up)

The notice using the "Model Explorer" on the right was faster to add these, but does however note that adding the classes and interfaces themselves in this toolbox (instead of using the toolbox on the left and clicking on the palette to create The object) won't create the objects in the diagram.

4. Creating IShape Interface

From Toolbox, select "Interface" and click somewhere in the chart. Rename it to IShape. Once created, select it.

      • In the top toolbar, select the "Stereotype Display" drop-down button to change the value to "None". This will change the default circular shape so that it becomes a rectangle.
      • On the top toolbar, uncheck "Suppress Operations". This will enable us to see the methods owned by the interface.

Add a Getarea method that returns a double to the IShape interface.

      • sets the return value type (☆). In the Model Explorer, expand the IShape node, right-click the Getarea method you just created, and select Add Parameter. In the Properties box, change the name of the parameter to NULL, change "Directionkind" to "RETURN", and Change "Type" to double.
      • Tick the IShape and Getarea's IsAbstract property boxes, and their names on the icons will be italic. This is the standard for UML, which means that this is an interface or other abstract entity.

5. Adding relationships for classes and interfaces

The circle implements the interface IShape by selecting the arrow representing "realization" from the toolbox and dragging it from circle to IShape. Repeat the same process to add the implementation relationship for rectangle. This is an implementation relationship that adds the circle and rectangle for the IShape interface.

Tip: If you want the connector to behave in a right-angled way, click the connector and select the Format-line style-rectilinear menu. In this way, you can make your diagram look neater by overlapping the arrows.

6. Adding class-based behavior on the interface

Since both the circle and the rectangle class implement the IShape interface, the same behavior (method) must be used. In the Model Explorer panel, copy the Getarea method (press Ctrl-c or right-click and select the Copy menu) and paste it into the circle and rectangle classes.

Note: These implemented methods are not abstract in the circle and rectangle classes, but are specific, so uncheck the IsAbstract box.

Now the class diagram should look like this:

7. Add Pizza Class

Adds a double-type private domain _price to pizza, adding a public operation GetPrice that returns a double type.

8. Add a ishape reference to the pizza class

Select the "directedassociation" Arrow from the Toolbox, click the Pizza class and drag it to IShape.

      • With the arrow selected, on the right "Properties" box, change the Name column to "Has-a" and the "end1.aggregation" column to "AGGREGATE" (this illustration shows that the pizza and Shape objects are "aggregated" relationships).
      • Change the "end2.name" column to _shape and change "end2.visibility" to private. This automatically adds a private domain named _shape that uses the IShape interface for pizza.

Create a "Winner" method for _shape, named Getshape, to return to IShape. This is the creation of a behavior whose name is Getshape and returns IShape.

9. Adding constructors

1. Add a constructor for pizza, right-click and select "Operation" in the pop-up "add" menu. From here, add an ordinary operation with the Dboule type price parameter and the IShape type shape parameter.

2. Add a constructor for circle with a radius parameter of type double.

3. Add a constructor with a double width and height parameter for rectangle.

Your diagram should now look like this:

10. Add Test_pizza Class

To illustrate the more functionality of UML class diagrams, a class called "Test_pizza" is added, which is used for testing purposes and used to Pizza and IShape classes.

      • Add dependencies between classes by selecting the "Dependency" Arrow from toolbox and dragging from one class to the class he has been in. In this example, Test_pizza relies on the Pizza, Circle, and rectangle classes because it instantiates them.
      • You can add a label to a dependency by selecting the Name property from the Properties box or by double-clicking the dependency line on the chart. In particular, when one class instantiates another, we call the dependency line "instantiates". You can select and drag the label of the dependent line to achieve a more aesthetically pleasing effect.
      • dependencies do not affect code generation.

The diagram should now look like the one at the beginning of this article.

11. Save & Export Project

Save: from the File menu, select Save. All of Su's information is only a single project file, so you should currently have only one file generated.

Export: exporting charts to other formats, examples, etc., is very useful. You can do this by selecting "Export Diagram" from the "File" menu and selecting the appropriate file type.

4. STARUML Advanced Application

1. Generate Java Stub code:

In the menu, select "Tools-java-generate Code".

      • Select your module from the dialog box (this may be Model1) and click "Next".
      • In order to generate stub code for all classes of your module or icon, choose "Select All" and press "Next".
      • Select a valid output directory, "Next".
      • In "Options Setup", be sure to select "Generate the documentation by JAVADOC", "Generate empty JavaDoc", all other check boxes unchecked, "Next".
      • Now STARUML will generate the code from your diagram and click "Finish" to exit the dialog box.
      • You can now edit the generated code to increase the app.

2. Add implementation code

As the beginning says, SU can generate code that reflects the class structure, rather than the concrete action of any object. Therefore, after you create a chart using Su, you should also add the remaining functional code for this stub, filling in what each method should do.

3. Reverse Engineering

STARUML can also create a class diagram from existing Java code, which is referred to as "reverse engineering". Reverse engineering is useful when you want to generate a chart from existing code, or if you modify the Su-generated code and want to react to it in a chart.

      • To the main menu bar, select "Tools-java-reverse Engineer ..." To reverse-engineer the existing code.
    • This article fixed link: http://www.flyne.org/article/379
    • Reprint Please specify: Dongfeng Huayu July 31, 2014 published in Flyne

Creating class diagrams using StarUML

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.