Composition Using Aggregation


Aggregation is a composition in which the whole subsumes and conceals its constituent parts as illustrated in the figure below. In contrast to an association, the parts of an aggregation are not visible externally, they do not have an identity as far as a user of the composition is concerned, and they do not possess autonomy to the same degree as parts of an association. The whole is the single visible entity. This suggests the following definition.

Aggregation
a composition that encapsulates (hides) the parts of the composition.

The figure Structure of an Aggregation shows the general model of an object defined by aggregation. The outer objects contain inner (encapsulated) subobjects which themselves may have hidden internal objects (sub-subobjects)..


Structure of an Aggregation

Composition using aggregation occurs in many familiar natural and man-made systems. The table below shows how several familiar systems can be mapped to the structure in the figure above.

Object Sub-Object Sub-Sub-Object
automobile engine pistons
computer mother board processor chip
molecules atoms quarks

An aggregation of objects is created when one object (the whole) contains in its encapsulated data one or more other objects (the parts). The simple one-second timer created above using association can also be implemented via aggregation as shown in the following figure. In this figure the basic objects that form the timer (Clock, Counter, TextBox, Frame, Start, and Stop) are contained within other objects (TimedCounter, Display and ControlButtons) that are, in turn, contained in the single encapsulating object, SimpleTimer. Notice that from the outside, only the SimpleTimer is visible; all other objects are concealed within the encapsulating boundary of the SimpleTimer object.

Composition via Aggregation

The first advantage of aggregation is that the outer object may be used without much, if any, concern for the operation, or even the existence, of the internal subobjects. When driving a car we are rarely concerned about the thousands of parts which are composed together to realize the car. The ability to ignore the finer structure of an object greatly simplifies the task of understanding how a system works or building a system that works in a particular way. The second advantage of aggregation is that internal parts may be changed without affecting the user's view of the external whole. The internal structure of the parts may be completely changed or only individual parts may be replaced. Improvement in efficiency, reliability, or cost may motivate the replacement of parts.

 




©1998 Prentice-Hall, Inc.
A Simon & Schuster Company
Upper Saddle River, New Jersey 07458

Legal Statement