Introduction to the Use tools of drawing class diagrams-startuml

Source: Internet
Author: User
Tags stub staruml drjava

STARUML Usage Instructions-instruction manual

STARUML is a tool for generating class diagrams and other types of Unified Modeling Language (UML) diagrams. This is a concise manual describing the creation of class diagrams in the Java language.

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

In this tutorial, we will use SU to design a pizza pie. Perform the following steps to create a UML diagram as shown below. Su can generate code that reflects the class structure, not concrete actions for any object. So, after using Su to create the chart, you add the remaining functional code to the stub code and fill in what each method should have done.

2. Installation

First, we must first install the software that will be used. STARUML is an open-source software that follows the GPL license (GNU Public License) and provides free downloads.

3. Start

You can start the program after installation.

4. Add New Project

Then a dialog box named: New Project by approach pops up. Select "Empty Project" and press "OK". It is recommended that you do not select the Set as Default check box.

5. Select Module

Select the untitled module in the Model Explorer box on the right.

6. Add Modules

Through the "model" main menu, or right click on the selected model, you can "Add/design model"

7. Add Class Diagram

You can "Add diagram/class Diagram" by using the "model" main menu, or by right-clicking the selected model:

8. Set profile

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.

9. Preservation Works

Save the project immediately so that you don't lose information when there is a problem.

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

10. Create charts

Now, start to really create the chart, from the default on the left side of the screen "Toolbox" Select the "Class" icon, 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.

11. Add Properties

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

L Specific data types, in the property panel (bottom right side of the window), by the doubles word, in the "type" period. 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 (fields/attributes) of the L class are private because they are strictly used internally by the class. So, in the Properties panel, set _radius to private.

12. Continue the design

Repeat the same process, add the so-called rectangle class and the private members of the double type _width and _height. (The following paragraph is the use of the idea of the matter, the total feeling that the translation department is too good, nine original moved up) The May notice using the ' Model Explorer ' on the ' right being faster to add ', but do however the adding and interfaces themselves in this toolbox (instead of using the "toolbox on the" and "clicking on" the Palette to create The object) won't create the objects in the diagram.

13. Create IShape Interface

L from Toolbox, select "Interface" and click somewhere on the chart. Change the name to IShape. After you create it, select it.

L at the top toolbar, select the "Stereotype Display" drop-down button to change the value to "None". This will change the shape of the previous circle, making it rectangular.

Or at the top of the toolbar, uncheck Suppress Operations. This will enable us to see the methods that the interface has.

L Add a Getarea method to the IShape interface with a return value of double.

n You can click the Red "Operation" button in the pop-up menu by right-clicking the interface icon, and then enter Getarea.

n Sets the return value type. Expand the IShape node in Model Explorer, right-click the Getarea method you just created, and select Add Parameter. In the Properties box, change the name of the argument to empty, change "directionkind" to "return", and change "Type" to Dboule.

L TICK the IsAbstract property box on the IShape and Getarea and their name on the icon will become italic. This is the standard of UML, which means that it is an interface or other pure virtual entity.

14. Add a relationship between a class and an interface

L The circle implements the interface IShape by selecting the arrow from the Toolbox that represents "realization" and dragging it from the circle to the IShape. Repeat the same process, adding implementation relationships for rectangle. This is the implementation of the circle and rectangle for the IShape interface.

n If you want the connector to behave as a right angle, right-click the connector and select the Format/line style/rectilinear menu. You can make your diagram look neater in this way by making the arrows overlap.

15. Adding a class based on the behavior of the interface

L because the circle and rectangle classes implement the IShape interface, they must have the same behavior (method).

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

N These implemented methods are not abstract in the circle and rectangle classes, but are specific. This is because they are actually performing certain behaviors (for example, calculating the area for a circle and rectangle), so do not check the IsAbstract box.

16. Your diagram should now be like this:

17. Add Pizza Class

L add a double private domain _price to pizza.

L Add a common operation GetPrice that returns a double type.

18. Add a IShape reference to the pizza class

L Select the "directedassociation" Arrow from Toolbox, click Pizza Class, and drag to IShape.

n Select the arrow, on the right side of the "Properties" box, change the Name column to "Has-a" and the "end1.aggregation" column to "AGGREGATE" (this illustration shows that pizza and Shape objects are "aggregation" relationships).

(n) Change the "end2.name" column to _shape. This automatically adds a pizza name to the _shape, using the IShape interface of the private domain, the so-called _shape type IShape to pizza pie.

N Change "end2.visibility" to private.

L Create a "winner" method for _shape, named Getshape, to return to IShape. This is the creation of an action, the name is Getshape, returned to IShape.

19. Adding constructors to the Pizza class

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

L Add an input parameter, just like an output parameter that adds a return type before, the name of the parameter you specify, such as price and shape, and the appropriate data type.

L Add a constructor with a double radius parameter for circle.

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

20. Your diagram should now be like this:

21. Add Test_pizza class

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

The relationship between the two classes has multiple forms. For example, a class can instantiate another class, rather than as a member. Or, a class of methods may require another class as an input parameter, and a reference is reserved only for the execution of this method.

L Add dependencies between toolbox classes by selecting the "Dependency" Arrow from a class and dragging it from one to his class. 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 Properties box, or by double-clicking on the chart, "dependent lines." In particular, when one class instantiates another, we call the dependency line "instantiates".

L You can select and drag the label of the dependency line to achieve a more beautiful effect.

L dependencies do not affect code generation.

22. Your diagram should now be as shown at the beginning of this article.

23. Make some changes to your diagram at your discretion.

You can also drag your class diagram and make the arrows appear in a way that doesn't work (make the arrows display as a line, select an arrow, right-click it, select Line Style in the pop-up menu, and select "Rectilinear"). You must experience the tool and understand it.

24. Save Project

From the File menu, select Save. All of Su's data has only one single project file, so you should have only one file to build at this time.

25. Export

It is useful to export a chart to another format, such as a picture. You can perform a modification by choosing Export Diagram from the "File" menu and selecting the appropriate file type.

26. Generate Java Stub code:

L Click on the "Tools->java" menu of the main menu and select "Generate Code".

L Select your module from the dialog box (which may be Model1 here) and click "Next".

L Create stub code for all classes of your module or icon, select "Select All" and press "Next".

L Select a valid output directory, "Next".

L in the "Options Setup", being sure to check both "Generate the documentation by JAVADOC" and "Generate empty Javadoc  ".  All other checkboxes should is unchecked. Then Press "Next". In "Options Setup", be sure to select "Generate the documentation by JAVADOC", "Generate empty Javadoc", all other check boxes are not selected, " Next ".

L now STARUML will generate code from your diagram, click "Finish" to exit the dialog box.

L Now you can edit the generated code to increase the application.

27. Add implementation Code

Start by defining what the program actually does, for example, adding implementation code to the class description in your icon.

L use Drjava to add code for the related class,.  Java file to add code. The code will be the same as you use HW02. (Note: For Test_pizza some code, it is best to be generated automatically by Drjava instead of manually creating it in STARUML.) We're here just to illustrate. )

L Remember that IShape's Getarea () method is abstract, so there is no code.

L ask you to add comments like code examples. This annotation is "JAVADOC" style. About Javadoc you will learn more later.

28. Reverse engineering

STARUML can also create a class diagram from existing Java code, known as "reverse engineering", which is useful when you want to generate diagrams from existing code, or if you modify the Su-generated code and want to react to it in a diagram. The process of working through a text editor such as a chart or Drjava is called "Round-trip engineering". This is also a basic process in which object-oriented becomes.

L Select "Tools/java/reverse Engineer ..." From the main menu bar to reverse-engineer the existing code.

Select the directory where the Java code is located and click the "Add" or "Add all" buttons to include them in the reverse engineering process, and then click Next.

Select the module you want to add the class to, which may be "Model1" and "next".

L in Option setup:

n Confirm "public", "package", "protected" and "private" are selected (this is the default setting).

n Similarly, by default, the radio button "Create the field to" is also selected.

n unless you want Su to create something else, such as a poorly laid out chart containing all the classes, do not select the Create Overview Diagram box.

n When you have checked the options, click "Run".

N SU would now import the classes in the selected files into your model. Click Finish to exit the dialog time it is complete. Sue now import class, in the selected file to the type of product you need, click "Finish" to exit the dialog box, completed.

L SU will add the imported class to your module, but not your chart. To add it to your diagram, simply drag them from Model Explorer.

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.