Jump to content

Aggregation (object-oriented programming): Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
{{merge|composition (computer science)|]]
No edit summary
Line 1: Line 1:
PRINCIPALITY OF GALORE!!!
{{merge|composition (computer science)|]]

{{cleanup-verify}}

'''Aggregation''' is a form of [[Composition (computer science)|composition]] where one looks at the system as a whole rather than as parts. It is also based on [[has-a]] [[relationship]] and is implemented by creating [[Object (computer science)|objects]] of other [[Class (computer science)|classes]] inside the class. An example will be a [[Automobile|car]] class which is an aggregation of different classes like [[wheel]], [[engine]], [[Car body|body]] etc.

Composition differs from aggregation in that composition indicates ownership. That is, in composition, when the containing object is destroyed, so are the contained objects. In aggregation, this is not necessarily true. For example, a [[university]] consists of various departments (e.g., [[chemistry]]), and each department contains a number of professors. If the university closes, the departments will no longer exist, but the professors in those departments will. Therefore, a University can be seen as a composition of departments, whereas departments have an aggregation of professors.

Composition is usually implemented such that an object contains another object. For example, in [[C plus plus|C++]]:

<pre>
class Professor;

class Department
{
...
private:
Professor faculty[20];
...
};
</pre>

In aggregation, the object may only contain a reference or pointer to the object:

<pre>
class Professor;

class Committee
{
...
private:
Professor* members[5];
...
};
</pre>

{{Compu-stub}}
[[Category:Object-oriented programming]]

Revision as of 08:18, 28 May 2005

PRINCIPALITY OF GALORE!!!