Lab Manual 6 1 31102020 125421pm
Lab Manual 6 1 31102020 125421pm
Object Composition
Objectives:
In real-life, complex objects are often built from smaller, simpler objects. For
example, a car is built using a metal frame, an engine, some tires, a transmission,
a steering wheel, and a large number of other parts. A personal computer is built
from a CPU, a motherboard, some memory, etc… Even you are built from smaller
parts: you have a head, a body, some legs, arms, and so on. This process of
building complex objects from simpler ones is called object composition.
In C++, you’ve already seen that structs and classes can have data members of
various types (such as fundamental types or other classes). When we build classes
with data members, we’re essentially constructing a complex object from simpler
parts, which is object composition. For this reason, structs and classes are
sometimes referred to as composite types.