Tuesday, February 19, 2013

Aggregation


Aggregation means HAS –A relationship

Eg: Employee has Address
ie-
class Employee{
int id;
String name,salary;
Address address;//Address is a class
}
employee -> name, id, salary also has Address -> which itself has different attribute like pincode, city, country etc.
When there is no IS-A relationship(ie: inheritance), best way of code reuse is aggregation.
Inheritance should be used only if the –IS-A relationship is maintained in the life time of the object, otherwise aggregation is the best choice.

No comments:

Post a Comment