AlarmClock object needs to know when it’s supposed to sound its alarm, so why not include a
Time object as a member of the
AlarmClock class? Such a capability is called composition and is sometimes referred to as a has-a relationship—a class can have objects of other classes as members.
Software Engineering Observation 9.9
A common form of software reusability is composition, in which a class has objects of other types as members.
Previously, we saw how to pass arguments to the constructor of an object we created in
main. Now we show how an class’s constructor can pass arguments to member-object ...