STARUML Instructions for use

Source: Internet
Author: User
Tags abstract documentation stub staruml drjava
Overview

STARUML is a tool that generates 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'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. Perform the following steps to create a UML diagram as shown below. Su can generate code that reflects the structure of the class, rather than the concrete action of any object. Therefore, after you create a chart using Su, you will add the remaining functional code for this stub, filling in the things that each method should do.

2. Installation

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

3. Start

The program can be started after installation.

4. Add a new project

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

5. Select the module

Select the "Untitled" module in the "Model Explorer" box on the right.

6. Add a module

"Model" main menu, or right-click the selected model, you can "Add/design model"

7. Add Class Diagram

You can "Add Diagram/class Diagram" via the "model" main menu, or right-click 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. 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:

10. Create a chart

Now, to really create the chart, choose the class icon from the toolbox 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.

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

L Specific data types, in the Properties panel (lower 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 (domain/attribute) of the L class is private because they are strictly used internally by the class. So, in the Properties panel, set the _radius to private.

12. Continue with the design

Repeat the same process by adding the so-called rectangle class and the private member of the double type _width and _height. (The following paragraph is the idea of the use of things, always feel the translation department is too good, nine 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.

13. 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 shape of the past round and make it into a rectangle.

On the top toolbar, uncheck "Suppress Operations". This will enable us to see the methods owned by the interface.

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

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

L TICK the IsAbstract property boxes of IShape and Getarea, and their names on the icons will be italic. This is the standard for UML, which means that this is an interface or other pure virtual entity.

14. Adding relationships for classes and interfaces

L can make the circle implement 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.

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

15. Adding class-based behavior on the interface

Because the circle and rectangle classes both 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, to calculate an area for a circle and a rectangle, respectively), so do not tick the IsAbstract box.

16. Your diagram should now look like this:

17. Add Pizza Class

L Add a double-type 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 the Pizza class and drag it to IShape.

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

N Change the column "End2.name" to _shape. This will automatically add a name for pizza to the _shape, using the IShape interface of the private domain, the so-called _shape type IShape with 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 a behavior whose name is Getshape and returns IShape.

19. Add a constructor to the pizza class

To 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

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

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

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

20. Your diagram should now look like this:

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

There are several forms of relationships between the two classes. For example, a class can instantiate another class instead of as a member. Or, a class of methods may require another class as an input parameter, leaving a reference only for the execution of this method.

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

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

L dependencies do not affect code generation.

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

23. Make some changes to your diagram.

You can also drag your class diagram and make the arrows appear in a non-linear manner (make the arrows visible in a straight line, select an arrow, right-click on it, choose Line Style from the pop-up menu, and select "Rectilinear"). You must experience this tool and get to know it.

24. Save the project

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.

25. Export

Exporting a chart to another format, such as a picture, is useful. You can do this by selecting "Export Diagram" from the "File" menu and selecting the appropriate file type.

26. Generate Java Stub code:

Click on the "Tools->java" menu in the main menu and select "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 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 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.
27. Add implementation Code

Now start defining what the program actually does, for example, adding implementation code for 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: To Test_pizza some code, it is best to generate it automatically by Drjava, rather than manually creating it in STARUML.) We're just here 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 kind of 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, which is called "reverse engineering", which is useful when you want to generate a diagram from existing code, or if you modify the Su-generated code and want to react to it in a chart. The process of repeating work through a text editor, such as a chart or Drjava, is called "Round-trip engineering". This is also an object-oriented into the basic process.

To the main menu bar, select "Tools/java/reverse Engineer ..." To reverse-engineer the existing code.

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

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

In option setup:

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

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

Do not select the "Create Overview Diagram" box unless you want SU to create something else, such as a poorly laid out chart that contains all the classes.

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

SU'll now imports the classes in the selected files into your model. Click "Finish" to exit the dialog when it was complete. Sue now imports the class, in the selected file to the product model you need, clicking "Finish" to exit the dialog box, it is completed.

Su will add the imported class to your module, but not your chart. To add it to your diagram, simply drag them from the Model Explorer. staruml Add villain (character) in the sequence diagram

Transferred from: http://blog.csdn.net/longyuhome/article/details/9011629
When looking at the timing diagram examples, found that some of the time series diagram has the villain's icon, but some of the UML tools did not find the icon of the villain, which makes me very upset, has not been resolved, today finally to solve the problem. Solve this problem from a suggestion on the Internet, the suggestion that the copy of a villain, but I did the copy of the time there is no success, today according to the proposal to study a bit, finally the villain (role) to add. Now share it with the people who need it.

The steps are as follows:

1. First create an empty project, as shown in the figure:

2. Then create a new model in the Model Explorer window on the right, as shown in the figure:

3. On the new Model1, add a time series diagram, as shown in the figure:

4. Then select the actor (role) under Add on the Model1, as shown in the figure:

5. Then add the villain to the timing diagram as shown in the figure below:

6, if you want to rename the role, do not double-click on the time series to rename, to add the villain just now rename, as shown in the figure:

This adds the villain (character) to the time series diagram, hoping to help the person in need.

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.