How to Draw Class Diagram?
A class diagram is a kind of UML diagram that shows the objects that are required and the relationships between them. Since it provides detailed information about the properties and interfaces of the classes, it can be considered as the main model and regard the other diagrams as supplementary models.
Creating class diagram
Perform the steps below to create a UML class diagram in Visual Paradigm.
In the New Diagram window, select Class Diagram.
Enter the diagram name and description. The Location field enables you to select a model to store the diagram.
Creating class
A class will be created.
Creating association
To create an associated class in a class diagram:
Move your mouse pointer over the source shape.
Press on the Resource Catalog button and drag it out.
Release the mouse button at the place where you want the class to be created. If you want to connect to an existing class, drop at that class. Otherwise, drop an the empty space (either at the diagram background or container shape like package).
If you are creating a new class, you should see the class now and it is connected to the source shape. Enter its name and press Enter to confirm editing.
The direction arrow is shown beside the association.
Creating generalization
To create a subclass:
Move your mouse pointer over the superclass.
Press on the Resource Catalog button and drag it out.
Release the mouse button at the place where you want the subclass to be created. If you want to connect to an existing class, drop at that class. Otherwise, drop an the empty space (either at the diagram background or container shape like package).
If you are creating a new class, you should see the class now and it is connected to the source shape with a generalization. Enter its name and press Enter to confirm editing.
Creating dependency from/to attribute/operation
You can also add a dependency from and/or to an attribute or operation in class. To create such a dependency.
Select Dependency from the diagram toolbar.
Press on the source shape or a class member.
Drag to the target shape, or a class member.
Release the mouse button to create the dependency.
Creating attribute
An attribute is created.
Creating attribute with enter key
After creating an attribute, press the Enter key, another attribute will be created. This method allows you to create multiple attributes quickly and easily.
Creating operation
An operation is created.
Similar to creating attribute, you can press the Enter key to create multiple operations continuously.
Showing just a parameter’s type
When the name of a parameter starts with “unnamed_”, its name will not be displayed in the class shape, leaving the parameter type (if defined).
Drag-and-Drop reordering, copying and moving of class members
To reord a class member, select it and drag within the compartment, you will see a thick black line appears to indicate where the class member will be placed.
Release the mouse button, the class member will be reordered.
To copy a class member, select it and drag to the target class while keep pressing the Ctrl key, you will see a thick black line appears indicating where the class member will be placed. A plus sign is shown beside the mouse cursor indicating this is a copy action.
Release the mouse button, the class member will be copied.
To move a class member, select it and drag to the target class, you will see a thick black line appears indicating where the class member will be placed. Unlike copy, do not press the Ctrl key when drag, the mouse cursor without the plus sign indicates this is a move action.
Release the mouse button, the class member will be moved.
Selecting all class members
To select all members within a class, you can select any member first, and then press Alt-A to select the rest.
Relating class members
Relationships such as dependency and generic connectors can be added between attribute and operation of classes. To do this:
Select the type of relationship to be created, under the diagram toolbar.
Move the mosue pointer over the source member.
Press on it and hold the mouse button.
Drag to the target member.
Release the mouse button to create the connector. While it looks like the connector is connecting the classes but not the members, if you check its specification you can see that the connector is indeed connecting the members.
Creating enumeration and adding enumeration literal
An enumeration is a special data type that consists of a pre-defined set of values, known as enumeration literals. Here are some of the common examples:
Color (RED, GREEN, BLUE)
Orientation (NORTH, SOUTH, EAST, WEST)
Switch (ON, OFF)
Then, enter the name of the literal and confirm editing.
Generalization set
Name the set in the Manage Generalization Sets window, and confirm by pressing OK.
The selected generalizations are grouped. Adjust the connector to make the diagram tidy.
Repeat the steps for other generalizations.
Defining delegate method for class
Hiding (and showing) attributes and operations
Per workspace
This applies to new classes that will be created in a project opened in specific workspace. To change the setting:
Open the Class tab.
Change the settings for Show attribute option and/or Show operation option.
Per diagram
This applies to classes in specific diagram. To change the setting:
Select Hide All / Show All / Show Public Only.
Per class
This applies to specific class. To change the setting:
Select Hide All / Show All / Show Public Only.
For specific attribute/operation
Instead of showing or hiding all members or public members, you may show/hide specific class member per class. To do this:
Select Customized under the drop down menu of Show.
Setting initial (default) value for attribute
Initial value can be set to an attribute, indicating the default value of the attribute when the owning object is instantiated. You can give a text value for initial value, or select an attribute of another class. To set initial value to an attribute:
In the General page of the specification window, enter the initial value in initial value field if it is a text value, or popup the drop down menu to select a public and static field of any class to be the value.
NOTE: In order to select the attribute of another class to be the default value, make sure the attribute you want to select is static (i.e. set to be in classifier scope) and is public (so that other classes can access).
Setting the ownership of association end
Subsetting on association end
Take a look at the sample below. The subset on d indicates that the collection d, which is an instance of class C, is a subset of the collection b, instance of class A.
To define a subset on an association end:
In the Association End Specification, open the Subsetted Association Ends tab.
Related Resources
The following resources may help you to learn more about the topic discussed in this page.