Aggregation Example
The incomplete classes below show a more complex example
of the use of aggregation.
A "community" is comprised of homes, a set of streets and has a name.
A "home" is comprised of rooms, an address and a yard.
A "room" is comprised of dimensions and a type.
An "address" is comprised of street number, street name, city,
state and zipcode.
As you look at these definitions, consider what some of the code
would look like as we remember the relationships among the classes.
- The Community can only use the
public interface provided by the House class (and the strings).
The Community cannot directly call any method
of the Address class, even though the House class uses an Address.
(similarly for the Rooms).
How would a member function of the Community gain access to
the street name of the first House?
- The House can only use the public methods of Room and Address.
How would a member function of the House access the 2nd Room's
type?