0% found this document useful (0 votes)
5 views

UMLClassDiagramTutorial

Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

UMLClassDiagramTutorial

Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

A UML Class Diagram Tutorial

The UML Class diagram is a graphical notation used to construct and visualize object oriented
systems.

A UML class diagram is made up of:


∙ A set of classes and

∙ A set of relationships between classes

What is a class?
A class in an object oriented system provides a crisp abstraction of a well defined set of
responsibilities.

A class consists of three parts: (Refer to the figure on the right)

parameters are shown after the colon


∙ Class Name:
following the parameter name.
o The name of the class appears in the first o Operations map onto class methods
partition. in code
∙ Class Attributes:
o Attributes are shown in the second
We can observe the following for
partition. MyClassName
o The attribute type is shown after the colon. The graphical representation of a Class
o Attributes map onto member
variables (data members) in code.
∙ Class Operations (Methods):
o Operations are shown in the third
partition. They are services the class
provides.
o The return type of a method is
shown after the colon at the end of
the method signature.
o The return type of method
∙ MyClassName has 3 attributes and 3 operations

∙ Parameter p3 of op2 is of type int

∙ op2 returns a float

∙ op3 returns a pointer (denoted by a *) to Class6

Page 1 of 8
Visibility and Access for attributes and operations of a class

The +, - and # symbols before an attribute and operation name in a class denote the visibility of
the attribute and operation.
+ denotes public attributes or operations
- denotes private attributes or operations
# denotes protected attributes or operations

We can observe that


∙ attribute1 and op1 of MyClassName are public

∙ attribute3 and op3 are protected.

∙ attribute2 and op2 are private.

Access for each of these visibility types is shown below for members of different classes.
Access public private protect
(+) (-) ed (#)

Members of the same class yes yes yes

Members of derived classes yes no yes

Members of any other class yes no no

Page 2 of 8
Operation (Method) Parameter Directionality

Each parameter in an operation (method) may be denoted as in, out or inout which specifies its
direction with respect to the caller. This directionality is shown before the parameter name.

These are briefly explained below:


Parameter direction Description

in states that p1 and p2 are passed to op1 by the


caller. They are both in parameters.

inout states that p3 is passed to op2 by the caller and is then


possibly modified by op2 and is passed back out. p3 is
an inout parameter.

out states that p6 is not set by the caller but is modified


by op3 and is passed back out.
p6 is an out parameter.

Page 3 of 8
Relationships between classes

A class may be involved in one or more relationships with other classes.

A relationship can be one of the following types: (Refer to the figure on the right for the
graphical representation of relationships)
Relationship Type Graphical Representation Inheritance (or
Generalization):
∙ Represents an “is-a” relationship.

∙ An abstract class name is shown in


italics.

∙ SubClass1 and SubClass2 are


specializations of SuperClass.
Association
∙ Simple association:
o A structural link between
two peer classes.
o There is an association
between Class1 and Class2

∙ Aggregation: A special type of


association. It represents a “part
of” relationship.
o Class2 is part of Class1.
o Many instances (denoted
by
the *) of Class2 can be
associated with Class1.
o Objects of Class1 and Class2
have separate lifetimes.

Page 4 of 8
∙ Composition: A special type of
aggregation where parts are
destroyed when the whole is
destroyed.
o Objects of Class2 live and
die with Class1.
o Class2 cannot stand by
itself.

∙ Dependency:
o Exists between two classes if
changes to the definition of
one may cause changes to
the other (but not the other
way around).
o Class1 depends on Class2

Page 5 of 8

You might also like