Showing the relationships among the classes is the most
important aspect of the Class diagram. To show the design pattern we need to
show the classes with their relationships. Let us understand different types of
relationships.
·
Association – Association is the simple relation between two
classes. In most of the cases it is the users relationship. Class A uses Class
B. Therefore, Class B is associated with Class A.
·
Generalization – Generalization is the Base class and child class
relationship.
·
Aggregation – Aggregation is the whole and part relationship.
Class A forms the part of Class B.
·
Composition – Composition is a special type of Aggregation where
the life time of the part is controlled by the Whole.
Figure 5 shows the Prototype design pattern showing the
relationships between the client, Prototype and the ConcretePrototype class.
Figure 5
·
Prototype – Declares the base interface for cloning itself(Base
class).
·
ConcretePrototype – Implements the declared interface for cloning
(Implements the base class). The relationship shown with the base class is
Generalization.
·
Client – Creates the new object by asking a prototype to clone
itself. Hence, the relationship is a simple Association.