How To Draw Class Diagram
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
To create a class in a class diagram, click Class on the diagram toolbar and then click on the
diagram.
Create class
Class created
Creating association
To create an associated class in a class diagram:
3. 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).
4. If you are connecting to an existing class, select Association from Resource Catalog. If
you are creating a new class, select Association -> Class from Resource Catalog. If you
want to create an aggregation or composition, select Aggregation -> Class or
Composition -> Class instead.
To create a class
5. 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.
To edit multiplicity of an association end, right-click near the association end, select
Multiplicity from the popup menu and then select a multiplicity.
Edit multiplicity
To show the direction of an association, right click on it and select Presentation Options >
Show Direction from the pop-up menu.
Show direction
Creating generalization
To create a subclass:
3. 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).
4. If you are connecting to an existing class, select Generalization from Resource Catalog.
If you are creating a new class, select Generalization -> Class from Resource Catalog.
To create a subclass
5. 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.
Subclass created
Selecting Dependency
Create attribute
An attribute is created.
Attribute created
Creating operation
To create operation, right click the class and select Add > Operation from the pop-up menu.
Create operation
An operation is created.
Operation created
Similar to creating attribute, you can press the Enter key to create multiple operations
continuously.
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).
Unnamed parameter
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.
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.
Selecting Dependency
Relationship created
To create an enumeration in the uml diagram tool, select Enumeration from the diagram toolbar
and click on the diagram to create one.
Create an enumeration
To add an enumeration literal, right click on the enumeration class and select Add >
Enumeration Literal from the popup menu.
Generalization set
A generalization set defines a particular set of generalization relationships that describe the way
in which a general classifier (or superclass) may be divided using specific subtypes. To define a
generalization set, select the generalizations to include, right click and select Generalization set >
Create Generalization Set... from the popup menu.
Name the set in the Manage Generalization Sets window, and confirm by pressing OK.
Name the generalization set
The selected generalizations are grouped. Adjust the connector to make the diagram tidy.
Adjust connector
This applies to new classes that will be created in a project opened in specific workspace. To
change the setting:
1. Select Window > Project Options from the toolbar to open the Options window.
2. Click Diagramming on the list.
3. Open the Class tab.
4. Click Presentation tab.
5. Change the settings for Show attribute option and/or Show operation option.
Show or hide operations
Per diagram
Instead of showing or hiding all members or public members, you may show/hide specific class
member per class. To do this:
1. Open the specification window of attribute by right clicking on the attribute and selecting
Open Specification... from the popup menu.
2. 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.
Selecting an initial value
In order to select the attribute of another class to be the default value, make sure
NOTE
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).
4. Click OK to confirm.
1. Right click on the association (where the subset end exist) and select Open
Specification... from the popup menu.
2. In the General tab, locate the association end where you want to define a subset. Click on
... for the Role property of the association end.
3. In the Association End Specification, open the Subsetted Association Ends tab.
4. From the list on the left hand side, click on the role you want to define subset for. Click >
to select it. If you do not see any role listing there, make sure your model respect the
pattern similar to the class diagram above - The class of both association ends are
subclasses, and there is an association connecting their superclasses.
5. Click OK to confirm and close the Association End Specification window.
6. Click OK to confirm and close the Association Specification window.
7. Right click on the association end and select Presentation Options > Show Association
End Property Strings from the popup menu to show the subset.
Related Resources
The following resources may help you to learn more about the topic discussed in this page.
You can create a UML Deployment diagram to show the architecture of a deployment of
software artifacts to nodes. First, you open the UML Deployment template and pick one of the
four template options. Then the UML Deployment stencil appears, along with shapes that
conform to the UML 2.5 standard.
DesktopWeb
1. Start Visio. Or if you have a file open already, click File > New.
2. Go to Categories > Software and Database > UML Deployment.
3. Select the blank template or one of the three starter diagrams. When you’ve picked the
template you want, click Create.
4. You should see the Shapes window next to the diagram. If you don’t see it, go to View >
Task Panes and make sure that Shapes is selected. If you still don’t see it, click the
Expand the Shapes window button on the left.
5. On the View tab, make sure the check box next to Connection Points is selected. This
will make connection points appear when you start connecting shapes.
6. Now, drag shapes you want to include in your diagram from the Shapes window to the
page. To rename text labels, double-click the labels.
Step 1
Drag a Node Instance shape to the page first, and then make it bigger by dragging the shape
handles.
Step 2
Drag an Artifact Instance shape and place it inside the larger node shape. When you see a green
highlight, this means the smaller shape will be contained within the larger node shape. From that
point forward, when the node shape moves, the artifact inside will move as well.
Other container shapes
There are other container shapes available in the UML Deployment stencil. They behave like
the Node Instance shape. That is, when you drop shapes on top of them, the shapes are glued and
will move with the container. Here are some of the most popular container shapes for
deployment diagrams:
Hierarchical nodes
Nest node shapes inside each other when you want to show them hierarchically.
Package shapes
Use Package shapes when you need to represent containing elements like a folder.
Diagram Overview
Use the Diagram Overview shape when you want to surround all of the shapes with a frame.
Tips for connectors
Straighten connectors
If a connector is taking too many turns, right-click it, and then click Straight Connector.
Show multiplicity
If needed, right-click the connector and select Show Multiplicity. When you’re done, four text
boxes appear where you can add details. If you do not need all the text boxes, delete the ones you
don’t need.
You can change a connector type. For example, you can change from an Association to a
Directed Association. Right-click the connector, and then click Set Connector Type.
If you anticipate moving shapes a lot, consider making a dynamic connection instead of a point
connection.
Most likely you’ll need to rotate or move text on your connector lines. Here’s how to do that:
1. Click an empty area of the page to deselect anything that may be selected.
2. On the Home tab, in the Tools group, click the Text Block tool
3. Click the connector that has text your want to rotate or move.
4. Drag the text block to move it, or rotate it using the Rotation Handle
5. When you’re done, click the Pointer Tool button
After you switch back to the Pointer Tool button , the text keeps the same position
relative to the shape. If you use the Pointer Tool to drag the text, the shape will also
move. To move the text independently of the shape, go back to the Text Block Tool .
Component shapes
When to use
Use component shapes for each functional unit in your system or application.
Show or hide stereotype
Interface shapes
When to use
1. Use the Provided Interface shape when you want to specify the realization of a
class/interface.
2. Use the Required Interface when you want to specify a dependency on a class/interface.
Step 1
Drag a Provided Interface shape to the page, and line up the port square with a connection
point. You know it’s connected when you see the green highlight around the connection point.
Step 2
Drag a Required Interface shape to the page, and line up the port square with a connection
point as well. You know it’s connected when you see the green highlight around the connection
point.
Step 3
To connect both a Provided and Required interface together, first select the Required Interface
shape. Then look for the yellow handle.
Step 4
You can create a UML component diagram to show components, ports, interfaces and the
relationships between them.
A component in UML represents a modular part of a system. The behavior is defined in terms of
required and provided interfaces. A component has an external view with public properties and
operations, and it has an internal view with private properties and realizing classifiers. The
internal view shows how external behavior is realized internally.
Newer versionsWeb2007–2010
First, you open the UML Component template and pick one of the four options. Then the UML
Component stencil appears, along with shapes that conform to the UML 2.5 standard.
Note: The UML Component stencil is only available if you are a Visio Plan 2 subscriber. If you
have a subscription, make sure you have the latest version of Visio.
1. Start Visio. Or if you have a file open already, click File > New.
2. Go to Categories > Software and Database > UML Component.
3. Select the blank template or one of the three starter diagrams. When you’ve picked the
template you want, click Create.
4. You should see the Shapes window next to the diagram. If you don’t see it, go to View >
Task Panes and make sure that Shapes is selected. If you still don’t see it, click the
Expand the Shapes window button on the left.
5. On the View tab, make sure the check box next to Connection Points is selected. This
will make connection points appear when you start connecting shapes.
6. Now, drag shapes you want to include in your diagram from the Shapes window to the
page. To rename text labels, double-click the labels.
Component shapes
When to use
Use component shapes for each functional unit in your system or application.
Subsystems
You can use the component shape as a subsystem shape that contains other components. Just
resize it to be larger, and drop other components on top of it. When you see the green highlight,
let go. From that point on the larger shape will act as a container, and the smaller shape will
move with it.
Tip: If a component disappears after dragging it on top of another component, then bring it to the
front by pressing CTRL+SHIFT+F.
Interface shapes
When to use
1. Use the Provided Interface shape when you want to specify the realization of a
class/interface.
2. Use the Required Interface when you want to specify a dependency on a class/interface.
Step 1
Drag a Provided Interface shape to the page, and line up the port square with a connection
point. You know it’s connected when you see the green highlight around the connection point.
Step 2
Drag a Required Interface shape to the page, and line up the port square with a connection
point as well. You know it’s connected when you see the green highlight around the connection
point.
Step 3
To connect both a Provided and Required interface together, first select the Required Interface
shape. Then look for the yellow handle.
Step 4
Straighten connectors
If a connector is taking too many turns, right-click it, and then click Straight Connector.
Show multiplicity
If needed, right-click the connector and select Show Multiplicity. When you’re done, four text
boxes appear where you can add details. If you do not need all the text boxes, delete the ones you
don’t need.
Change connector type
You can change a connector type. For example, you can change from an Association to a
Directed Association. Right-click the connector, and then click Set Connector Type.
If you anticipate moving shapes a lot, consider making a dynamic connection instead of a point
connection.
Most likely you’ll need to rotate or move text on your connector lines. Here’s how to do that:
1. Click an empty area of the page to deselect anything that may be selected.
2. On the Home tab, in the Tools group, click the Text Block tool
3. Click the connector that has text your want to rotate or move.
4. Drag the text block to move it, or rotate it using the Rotation Handle
5. When you’re done, click the Pointer Tool button
After you switch back to the Pointer Tool button , the text keeps the same position
relative to the shape. If you use the Pointer Tool to drag the text, the shape will also
move. To move the text independently of the shape, go back to the Text Block Tool .
A UML sequence diagram shows how a set of objects interact in a process over time. It shows
the messages that pass between participants and objects in the system, and the order in which
they occur.
Newer desktop versionsWeb2007–2010
To build a sequence diagram, use a UML Sequence template or starter diagram, which includes
the UML Sequence stencil. Drag shapes from the stencil onto the drawing canvas to build the
diagram.
1. Start Visio. Or if you have a file open already, click File > New.
2. In the Search box, type UML sequence.
3. Select the UML Sequence diagram.
4. In the dialog box, select the blank template or one of the three starter diagrams. (A
description of each one is shown on the right when you select it.) Then select either
Metric Units or US Units.
5. Select Create.
6. The diagram opens. You should see the Shapes window next to the diagram. If you don’t
see it, go to View > Task Panes and make sure that Shapes is selected. If you still don’t
see it, click the Expand the Shapes window button on the left.
7. On the View tab, make sure the check box next to Connection Points is selected. This
option makes connection points appear when you start connecting shapes.
8. Now, drag shapes you want to include in your diagram from the Shapes window to the
page. To rename text labels, double-click the labels.
Use an Actor lifeline shape for each participant, and an Object lifeline shape for each system
component in your process.
Tip: As you drag the lifelines into place, green alignment guides appear onscreen to help you
line up and space the lifelines relative to the other lifeline shapes.
Double-click in the heading box for each lifeline to enter a name or title.
To lengthen or shorten a timeline, click the lifeline, then drag the yellow control point at
the bottom of the lifeline.
Messages
Tip: Visio helps you glue the message endpoints to each lifeline. A green circle appears at the
endpoint when it glues to a connection point. The connections points disappear when you are
done dragging.
Attach the beginning endpoint to the lifeline sending the message, then drag the head
endpoint to the lifeline receiving the message.
Double-click the message shape to create a text box, and type a name for the message.
Use a Message shape (a solid line) to represent a request or the transmitting of
information.
Use a Return Message shape (a dashed line) to represent a response to a prior message.
Use a Self Message to represent a recursive call of an operation, or one method calling
another method belonging to the same object.
Use the Asynchronous Message shape to show when an action might not happen
immediately.
To change the shape of a connector message:
a. Right-click the connector.
b. At the bottom of the pop-up menu, select from the three options (Right-Angle,
Straight, Curved).
c. Click and drag the connector to change its shape.
Fragments
If one or more interactions form a loop, or require a condition to be met to end the interaction,
enclose those interactions in a fragment shape:
Drag the fragment shape to the interactions it relates to. Use the sizing handles on the
fragment shape to ensure it encloses all of the related interactions.
Double-click in the title corner of the fragment shape to add a title or short description of
the process enclosed by the fragment. Below the title corner, click the [parameters]
prompt if you want to enter the conditions that would end that process.
Activation
Place an Activation bar shape on a lifeline to show when and for how long that object or
participant is active in the process. Typically, there will be arrows going to and from an
activation box to demonstrate the flow of information.
Drag the endpoints of the Activation bar up or down to make it the length that you want.
Destruction
Activity Diagrams consist of activities, states and transitions between activities and states which
describe how activities are coordinated to provide a service, such as, how the events in a single
use case relate to one another, or how a collection of use cases coordinate to create a workflow
for an organisation
2. In the New Diagram window, select Activity Diagram, then click Next. You can use the search
bar above to filter diagrams.
3. Name the diagram, then click OK. In this tutorial, the diagram will be named Activity Diagram
Tutorial. You will then see an empty diagram.
4. Select Vertical Swimlane, then click any empty space on the diagram.
If you cannot findVertical Swimlane, try click the small triangle next to Horizontal Swimelane,
you will then see Vertical Swimlane.
5. You can rename partitions by double clicking the name of each partition. The first two
participants in this tutorial are Customer and Sales.
6. To create more partitions, right click any empty space on the swimlane, then select Add Vertical
Partition.
9. To create an action, click the initial node, click and hold the resource button, then drag to the
desire location. When release the button, choose Control Flow > Action. You can rename the
action afterwards by double clicking the action.
A state machine Diagram (or start diagram, also called state chart of state transition diagram) is a
behavior which specifies the sequence of states an entity (or object) visits during its lifetime in
response to events, together with its responses to those events.
Key concepts
State
A state is a condition during the life of an object during which it satisfies some condition,
performs some activity, or waits for some external event
Event
A transition is a relationship between two states indicating that an object in the first state will,
when a specified set of events and conditions are satisfied, perform certain actions and enter the
second state.
Action
An action is an executable, atomic (with reference to the state machine) computation. Actions
may include operations, the creation or destruction of other objects, or the sending of signals to
other objects (events).
2. In the New Diagram window, select State Machine Diagram, then click Next. you can use the
search bar above to filter results.
3. Name the diagram, then click OK. In this tutorial, we will name the diagram State Machine
Diagram Tutorial.
4. You will now see an empty diagram with an initial pseudo state.
5. To Create a new state, click the initial state, then drag the resource button to the desire
position and release. When release the button, choose Transition -> State from the popup
window. Once the state is created, you may change the name of the state.
8. Once all the states are created, you may want to set up more transitions. You can do this by
selecting Transition, click and hold on the starting state (Sold in this example), then drag to the
destination state (Available in this example) and release. Do not forget to name the transition.
9. You are expected to see a diagram like this when you finish your diagram:
Use-case:
Use cases are used to represent high-level functionalities and how the user will handle the
system. A use case represents a distinct functionality of a system, a component, a package, or a
class. It is denoted by an oval shape with the name of a use case written inside the oval shape.
The notation of a use case in UML is given below:
Actor:
It is used inside use case diagrams. The actor is an entity that interacts with the system. A user is
the best example of an actor. An actor is an entity that initiates the use case from outside the
scope of a use case. It can be any element that can trigger an interaction with the use case. One
actor can be associated with multiple use cases in the system. The actor notation in UML is given
below.
A use case is nothing but a core functionality of any working system. After organizing the use
cases, we have to enlist the various actors or things that are going to interact with the system.
These actors are responsible for invoking the functionality of a system. Actors can be a person or
a thing. It can also be a private entity of a system. These actors must be relevant to the
functionality or a system they are interacting with.
After the actors and use cases are enlisted, then you have to explore the relationship of a
particular actor with the use case or a system. One must identify the total number of ways an
actor could interact with the system. A single actor can interact with multiple use cases at the
same time, or it can interact with numerous use cases simultaneously.
Following rules must be followed while drawing use-case for any system:
1. The name of an actor or a use case must be meaningful and relevant to the system.
2. Interaction of an actor with the use case must be defined clearly and in an understandable
way.
3. Annotations must be used wherever they are required.
4. If a use case or an actor has multiple relationships, then only significant interactions must
be displayed.
In the above use case diagram, there are two actors named student and a teacher. There are a total
of five use cases that represent the specific functionality of a student management system. Each
actor interacts with a particular use case. A student actor can check attendance, timetable as well
as test marks on the application or a system. This actor can perform only these interactions with
the system even though other use cases are remaining in the system.
It is not necessary that each actor should interact with all the use cases, but it can happen.
The second actor named teacher can interact with all the functionalities or use cases of the
system. This actor can also update the attendance of a student and marks of the student. These
interactions of both student and a teacher actor together sums up the entire student management
application.
The use case diagrams represent the core parts of a system and the workflow between them. In
use case, implementation details are hidden from the external use only the event flow is
represented.
With the help of use case diagrams, we can find out pre and post conditions after the interaction
with the actor. These conditions can be determined using various test cases.
Use cases are intended to convey desired functionality so the exact scope of a use case may vary
according to the system and the purpose of creating UML model.
Summary
Use case diagrams are a way to capture the system’s functionality and requirements in
UML diagrams.
It captures the dynamic behavior of a live system.
A use case diagram consists of a use case and an actor.
A use case represents a distinct functionality of a system, a component, a package, or a
class.
An actor is an entity that initiates the use case from outside the scope of a use case.
The name of an actor or a use case must be meaningful and relevant to the system.
A purpose of use case diagram is to capture the core functionalities of a system.