Monday, April 16, 2007

Aggregation and Association

Object Association :


In object association, one object is formed from the union of two or more other objects.

In object-oriented programming, there are two kinds of object association, aggregation and composition. Both intend to do the same thing, build "large" objects from "smaller" ones. They differ only conceptually, from an object system perspective.


Composition :
--------------
composite types are datatypes which can be constructed in a programming language out of that language's primitive types and

other composite types. The act of constructing a composite type is known as composition.

struct Account
{
int account_number;
char *first_name;
char *last_name;
float balance;
};


Recursive Composition :
------------------------

struct bintree {
struct bintree *left, *right;
// some data
};





Aggregation :
-------------

Composited (composed) objects are called fields, items, members or attributes, and the resulting composition a structure, record, tuple,

user-defined type (UDT), or composite type. The terms usually vary across languages. Fields are given a unique name so that each one can be distinguished from the others.

Sometimes an issue of ownership arises: when a composition is destroyed, should objects belonging to it be destroyed as well?
If not, the case is sometimes called aggregation.

No comments: