Every classifier in the class diagram relate to another classifier through one of the following relationship:
- Dependency: If class A is using the state or behavior of another class B for initializing its state or performing his responsibility, Then we say that class A depends on class B. It is show by a dashed arrow line from A into B.
- Interface implementation: If class A implements an interface IA in the class diagram then we say A implements IA. In pure object oriented languages one class can implement many interfaces. In UML it is denoted by a dashed line with an un-filled triangle into IA from A.
- Inheritance: If class A extends another class B. The it is a parent (B) Chile (A) relationship. In pure object oriented languages one class can extend only one another class unlike interfaces. Inheritance is shown by a solid line from child into parent with an un-filled triangle.
- Association: If class A initializes class B instance for a short time of span for accessing its state or behavior and then the instance gets destroyed then we call it an association. In other words class A uses class B services for a short time. It is denoted by a solid line between classifier. I uni-directional then optional arrow can be added into B class, Otherwise for bi-directional association no arrow is shown.
- Aggregation: If class A uses class B for its whole life and have no control on the life of instance B then we call it aggregation. One possibility for this relationship is when you pass instance of B as parameter to constructor of A. Aggregation allows Dependency Injection (DI) also called Inversion of Control (IoC) principle, which is the base of latest development trend for test driven development TDD. It is denoted by an un-filled diamond into A with a solid line from B.
- Composition: If class A uses class B for its whole life and also control the life of instance B then we call it composition. One possibility for this relationship is when initialize instance of B in constructor of A or at class level. This is also a whole part relationship. It is denoted by an filled diamond into A with a solid line from B.