Class Diagrams Notes
Class Diagrams Notes
In software engineering, a class diagram in the Unified Modeling Language (UML) is a type of
static structure diagram that describes the structure of a system by showing the system's
classes, their attributes, operations (or methods), and the relationships among objects.
What is a Class
A description of a group of objects all with similar roles in the system, which consists of:
Class Notation
A class notation consists of three parts:
1. Class Name
o The name of the class appears in the first partition.
2. Class Attributes
o Attributes are shown in the second partition.
o The attribute type is shown after the colon.
o Attributes map onto member variables (data members) in code.
3. 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 parameters are shown after the colon following the
parameter name.
o Operations map onto class methods in code
Simple Association:
Aggregation:
Composition:
Dependency:
Relationship Names
Relationship - Roles
Navigability
The arrows indicate whether, given one instance participating in a relationship, it is possible to
determine the instances of the other class that are related to it.
The diagram above suggests that,
Given a spreadsheet, we can locate all of the cells that it contains, but that
o we cannot determine from a cell in what spreadsheet it is contained.
Given a cell, we can obtain the related expression and value, but
o given a value (or expression) we cannot find the cell of which those are
attributes.
The +, -, # and ~ symbols before an attribute and operation name in a class denote the visibility
of the attribute and operation.
Access for each of these visibility types is shown below for members of different classes.
Access Right public (+) private (-) protected (#) Package (~)
Members of the same class yes yes yes yes
Members of derived classes yes no yes yes
Members of any other class yes no no in same package
Multiplicity
How many objects of each class take part in the relationships and multiplicity can be expressed
as:
Exactly one - 1
Zero or one - 0..1
Many - 0..* or *
One or more - 1..*
Exact Number - e.g. 3..4 or 6
Or a complex relationship - e.g. 0..1, 3..4, 6.* would mean any number of objects other
than 2 or 5
Multiplicity Example
Requirement: A Student can take many Courses and many Students can be enrolled in
one Course.
In the example below, the class diagram (on the left), describes the statement of the
requirement above for the static model while the object diagram (on the right) shows
the snapshot (an instance of the class diagram) of the course enrollment for the courses
Software Engineering and Database Management respectively)
Aggregation Example - Computer and parts
An aggregation is a special case of association denoting a "consists-of" hierarchy
The aggregate is the parent class, the components are the children classes
We can interpret the meaning of the above class diagram by reading through the points as
following.