OOPortal OOPortal


Analysis Design Concepts  «Prev  Next»
Lesson 6The concept of Aggregation:
ObjectiveDefine aggregation as it applies to object modeling.

Define Aggregation in Object Modeling

Working with aggregates

Aggregation describes the assembly of objects to create a new object where the whole (the assembly) is greater than the sum of the parts.
One the part objects are assembled into an aggregate, they are essentially hidden. The part objects become the implementation of the aggregate. To use the aggregate, the client objects must access the interface of the aggregate object. The part objects are inaccessible.

Propagation

When the aggregate interface is invoked, the aggregate propagates the instruction, that is, it sends instructions to its parts to implement the requested function. The aggregate has no behavior of its own other than to coordinate the behavior of its parts. For example, a car is made up of an engine, transmission, fuel system, and other parts. When drivers want to move the car forward, they use the interface of the car, that is, the ignition switch, the gas pedal, the brake pedal, and so on, rather than access the parts directly. For example, a press of the gas pedal is implemented when the fuel system pumps gas, the engine turns over, and the transmission responds to the speed changes. Aggregation is not reflected in code. The implementation looks like any other association. Use aggregation to show intent. The intent of aggregation is to hide the makeup of a complex object by requiring client objects to talk to the aggregate.

Aggregation versus composition

Aggregation defines an object in terms of the parts assembled to make it. When you want the parts to be available for use even when the aggregate is dissembled, you are using weak aggregation. If the parts exist only as long as they are part of the aggregate, you are using strong aggregation, or composition.
The SlideShow below describes an example of both weak and strong aggregation (composition):



1) Weak aggregation: Players may participate in many teams at the same time. For example, they can play for a city league and a company team
2) Strong aggregation or Composition: Chapters belong to a specific book. Without the book the chapters have no context and lose their meaning.

Weak Strong Aggregation
Aggregation and composition can represent an infinite number of layers of detail.
However, remember to include only the level of detail needed to support the abstraction required by the problem domain.