What is aggregation?

Answer Posted / bnaga

# Aggregation: If class have an entity reference,it is known as Aggregation. Aggregation represents HAS-A relationship.
Suppose.
Let suppose person have lots of information like name, address,phone number , id , education. so here we can further divide education in parts of education like
1)Post graduation
2)Graduation
3)Senior secondary
4)Higher secondary
in this case person have entity reference education

For example:

/*
class Person{
String name;
int id;
int Monumber;
String educatoin//entity refrence

}
*/

Why we use Aggregation : for code reusability in program.


By example :

Education.java
/*
public class Education {
String postgraduation,gradution,seniorsecondary,highersecondary;

public Education(String postgraduation,
String gradution,String seniorsecondary,String highersecondary) {

this.postgraduation = postgraduation;
this.gradution = gradution;
this.seniorsecondary = seniorsecondary;
this.highersecondary = highersecondary;
}

}

*/


Persona.java
/*
class Person{
String name;
int id;
Education edu; // entity reference

Person( String name, int id, Education edu){

this.name = name;
this.id = id;
this.edu = edu;
}

void showdata(){

System.out.println("Name:="+name+"Id:="+id);
System.out.println(edu.postgraduation+""+ edu.gradution+""+edu.seniorsecondary+""+edu.highersecondary)
}
public static void main(String args[]){
Education ed1 = new Education("MSC","BSC","10th","12th");
Education ed2 = new Education("MSC","BSC","10th","12th");

Person p1 = new Person("Bang",1,ed1);
Person p2 = new Person("Babu",2,ed2);

p1.showdata();
p2.showdata();

}
}
*/

Aggregatoin(HAS-A) is better than Composition(IS-A) relationship.

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the purpose of the return statement?

506


What exactly is methodology?

474


Are maps ordered java?

502


Can you explain the private protected field modifier?

561


Why java is a platform independent? Explain

527






What is an error in java?

633


What is a bubble sort in java?

535


What is meant by javabeans?

606


What is thread count in java?

538


Where are local variables stored?

505


Is it possible to override the main method?

525


Is 0 an irrational number?

590


What is use of static method?

528


Name the components that are termed to be Heavy-weight component but available in Light-weight components?

1979


How can I become a good programmer?

482