When a class inherits another class, we often say that the child class is a kind of parent class. If a car takes the benefits of a vehicle class, for example, we say that a car is a kind of vehicle. In inheritance, classes always have an is-a relationship. In this section, we will discuss two more important topics related to object-oriented programming, in which classes have a has-a relationship instead. These concepts are aggregation and composition. Let's start by looking at aggregation.
Aggregation, composition, and nested classes
Aggregation
When an object contains another object in its body, the relationship between them is called aggregation. This is a loosely-coupled relationship between two objects, in which one...