Class Diagram Tutorial
Class Diagram Tutorial
Operation
The operations are documented in the bottom compartment of the class diagram's
rectangle, which also is optional. Like the attributes, the operations of a class are
displayed in a list format, with each operation on its own line. Operations are documented
using this notation: name (parameter list) : type of value returned (e.g. calculateTax
(Country, State) : Currency).
Relationships
Association
Some objects are made up of other objects. Association specifies a "has-a" or
"whole/part" relationship between two classes. In an association relationship, an object
of the whole class has objects of part class as instance data.
In a class diagram, an association relationship is rendered as a directed solid line.
Unidirectional association - In a unidirectional association, two classes are related, but
only one class knows that the relationship exists.
A unidirectional association is drawn as a solid line with an open arrowhead pointing to
the known class.
Multiplicity
Place multiplicity notations near the ends of an association. These symbols indicate the
number of instances of one class linked to one instance of the other class. For example,
one company will have one or more employees, but each employee works for one
company only.
Visibility
Visibility is used to signify who can access the information contained within a class
denoted with +, -, # and ~ as show in the figure:
Generalization
A generalization is a relationship between a general thing (called the superclass) and a
more specific kind of that thing (called the subclass). Generalization is sometimes called
an "is a kind of" relationship and is established through the process of inheritance.
In a class diagram, generalization relationship is rendered as a solid directed line with a
large open arrowhead pointing to the parent class.
Realization
A realization is a relationship between two things where one thing (an interface) specifies
a contract that another thing (a class) guarantees to carry out by implementing the
operations specified in that contract.
In a class diagram, realization relationship is rendered as a dashed directed line with an
open arrowhead pointing to the interface.
Dependency
Dependency indicates a "uses" relationship between two classes. In a class diagram, a
dependency relationship is rendered as a dashed directed line.
If a class A "uses" class B, then one or more of the following statements generally hold
true:
1. Class B is used as the type of a local variable in one or more methods of class A.
2. Class B is used as the type of parameter for one or more methods of class A.
3. Class B is used as the return type for one or more methods of class A.
4. One or more methods of class A invoke one or more methods of class B.