Hướng dẫn vẽ class diagram

Create a Class diagram

Go to [Diagram] – [Class Diagram] to create a Class diagram.


Auto-create Class diagrams

You can automatically create Class diagrams of a package.

  1. If you have source code, import first to Astah.
    – How to import Java source code
    – Use Plug-ins to import source code (C++, C#, and Java)
  2. Right-click on a package in a tree view and select [Auto Create Class Diagram]

  3. Now you have three options.

1. Simple

This creates a class diagram without Attributes and Operations inside the classes.

2. Detailed

This creates a class diagram with Attributes and Operations inside the classes.

3. Unpack Subpackages

This creates a class diagram with the whole models including models inside the sub-packages if the package you select has sub-packages.

Creating a Class

You can find out 5 ways to create a Class in the Diagram Editor page.

Template Class

You can create a Template Class by adding Template Parameters to a class. There are two ways to do so.

  1. Select [Add Template Parameter] from Class’s Pop-up menu
  2. Define details at the bottom-left pane under [Template Class].

Attributes

You can create Attributes by clicking the orange diamond that appears when you have a mouse over a Class.

Also, you can create another attribute by hitting the [Enter] key while an attribute is selected.

Since version 8.5, you can add Attributes by pasting a copied text.

Attribute Visibilities

There are several ways to show/hide attributes.
In order to change the visibility of attributes on a currently-opened diagram, open the [Initial Visibility] tab from the left-bottom pane in Astah and check the options you want in a diagram and click the [Apply to existing elements] button.

Operations

You can create Attributes by clicking a green bar that appears when you have a mouse over a Class.

Also, you can create another attribute by hitting [Enter] key while an attribute is selected.


Moving Attributes/Operations

You can move around attributes/operations by dragging them to another class or within a class.

Since version 8.5, you can add Operations by pasting a copied text.

Anonymous Bound Class

You can create an anonymous bound class by deleting the name of Bound Class.

Anonymous Bound Classes can be specified to the following:

  • Attribute Type
  • Operation Return Value
  • Operation Parameter Type
  • The target of Association End A and Association End B
  • Base Class of Instance Specification in Class
  • Base Class of Object Node in Activity Diagram
  • Base Class of Lifeline in Sequence Diagram and Communication Diagram

Example of creating a Bound Class

  1. Create a abound class.
  2. Create a new class and add an attribute whose type is bound class to it.
  3. When you add the class, you will be asked if you’d like to create a new class. Click [Yes].
  4. Click [Show Hidden Relationship] from its pop-up menu.
  5. Then you will get the relationship of the anonymous bound class.

Nest a Class

You can have a class nested to a package by dragging it into a Package.

Association

You can create associations by choosing an association type from a small icon list that appears when you hover a mouse over a class, then directly click on the target class.


Please refer to “Drawing Lines” for more information.

Jump to Association Ends

You can jump to the Association ends from association line’s pop-up menu.

  1. Right-click on the Association and select [Move to related element].
  2. Select one that you want to jump to.

Relocate Association name

As your diagram gets complex, association names could be left out and end up being far away from the association line.
In that case, you can bring the association name back to the center of the association line.
Right-click on an association line and click [Init Label Position].

Chủ đề