Skip to main content

Four class relationships from figure

Short answer

The four key relationships are dependency (dashed arrow for a uses-a relationship), association (solid line with multiplicity, including aggregation hollow diamond and composition filled diamond), generalization (hollow triangle for is-a inheritance), and realization (dashed hollow triangle for implementing an interface).

Explain four different types of relationships that we model in object-oriented analysis, which exists between two different classes represented as shown in below figure. [Figure: two class boxes connected by relationship arrows; the figure is not legible in the scan.]

The figure is not legible, so the four standard relationships that UML models between two classes are explained with their notation: dependency, association, generalization and realization (the four listed in the UML User Guide). Aggregation and composition are covered as special forms of association.

1. Dependency

A weak, temporary "uses" relation: a change in the supplier may affect the client, e.g. when the supplier is a method parameter or local variable. Drawn as a dashed arrow towards the supplier.

 +---------+  - - - - ->  +--------+
 | Printer |   <<use>>    | Report |
 +---------+              +--------+

2. Association (with aggregation and composition)

A structural link between objects of two classes ("knows/is linked to"). Drawn as a solid line, with a name, role names and multiplicity.

 +---------+ 1      0..* +---------+
 | Teacher |-------------| Student |
 +---------+  teaches    +---------+

A teacher teaches many students.

Aggregation is a "has-a" (whole-part) association where the part can exist without the whole (hollow diamond at the whole). Composition is a strong form where the part dies with the whole (filled diamond).

 +-------+ <>-------- +--------+   hollow: aggregation
 | Team  |            | Player |
 +-------+ <#>------- +--------+   filled: composition
 | House |            | Room   |

3. Generalization (inheritance)

An "is-a" relation between a general superclass and specialised subclasses. Drawn as a solid line with a hollow triangle at the superclass.

        +--------+
        | Person |
        +--------+
            ^
      +-----+-----+
 +---------+ +---------+
 | Student | | Teacher |
 +---------+ +---------+

4. Realization

A relation between an interface (a specification) and the class that implements it; the class promises to provide all the interface's operations. Drawn as a dashed line with a hollow triangle pointing to the interface.

 +---------------+
 | <<interface>> |
 |   Printable   |
 +---------------+
         ^
         :  (dashed, hollow triangle)
 +---------------+
 |    Invoice    |
 +---------------+

✓ Answer checked by Claude Opus 5.5 (high effort)

All Object Oriented Analysis and Design chapter 2 questions →