[go: up one dir, main page]

0% found this document useful (0 votes)
4 views5 pages

Aggregation

Uploaded by

jawadkh8180
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views5 pages

Aggregation

Uploaded by

jawadkh8180
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Aggregation

Aggregation is a special case of association.

In Aggregation the dependent object is standalone and can exist even


if the object of owning class is dead.

A directional association between objects.

When an object has a another object, then you have got an aggregation
between them.

Direction between them specified which object contains the other object.

Aggregation is also called a “Has-a” relationship.

Example:

A Library contains students and books. Relationship between library and


student is aggregation.

Composition

Composition is a special case of aggregation.

In a more specific manner, a restricted aggregation is called composition.

When an object contains the other object, if the contained object cannot
exist without the existence of container object, then it is called
composition.
Also called "death relationship”

Example: A class contains students. A student cannot exist without a


class. There exists composition between class and students.

A Library contains students and books. Relationship between library and


book is composition.

Difference between aggregation and composition

Composition is more restrictive.

When there is a composition between two objects, the composed object


cannot exist without the other object. This restriction is not there in
aggregation. Though one object can contain the other object, there is no
condition that the composed object must exist. The existence of the
composed object is entirely optional. In both aggregation and
composition, direction is must. The direction specifies, which object
contains the other object.
#include<iostream.h>

#include<conio.h>

class A

public:

char *name;

int id;

A(char *na, int n)

name=na;

id=n;

};

class B

private:

A *ab;

public:

int clas;

char *section;

B(int cl, char *sec, A *tem)

clas=cl;

section=sec;

ab=tem;
}

void put()

cout<<clas;

cout<<section;

cout<<ab->name;

cout<<ab->id;

};

void main()

clrscr();

A a("BSSE",123);

B b(345,"B",&a);

b.put();

getch();

You might also like