Question: JAVA: Aggregation Aggregation in Java is a relationship between two classes that is best described as a has - a and whole / part

JAVA: Aggregation Aggregation in Java is a relationship between two classes that is best described as a "has-a" and "whole/part" relationship. It is a more specialized version of the association relationship. The aggregate class contains a reference to another class and is said to have ownership of that class. Each class referenced is considered to be part-of the aggregate class. Ownership occurs because there can be no cyclic references in an aggregation relationship. If Class A contains a reference to Class B and Class B contains a reference to Class A then no clear ownership can be determined and the relationship is simply one of association. For example, if you imagine that a Student class that stores information about individual students at a school. Now assume a Subject class that holds the details about a part Example: Define an aggregation relationship between Student class and the Subject class as follows: public class Subject { private String name; public void setName(String name){ this.name = name; } public String getName(){ return name; }} public class Student { private Subject[] studyAreas = new Subject[10]; //the rest of the Student class } Association Association refers to the relationship between multiple objects. It refers to how objects are related to each other and how they are using each other's functionality. Composition and aggregation are two types of association. Composition The composition is the strong type of association. An association is said to composition if an Object owns another object and another object cannot exist without the owner object. Consider the case of Human having a heart. Here Human object contains the heart and heart cannot exist without Human. Aggregation Aggregation is a weak association. An association is said to be aggregation if both Objects can exist independently. For example, a Team object and a Player object. The team contains multiple players but a player can exist without a team.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!