What is aggregation in Java explain with an example
The main purpose of aggregation is reusability.As an example, think about the phone numbers on your cell phone.Here uber (company) is whole part and cab driver (person) is part.Aggregation is a term which is used to refer one way relationship between two objects.Let us take a situation;
We have two types of relationships one is has a and other is is a relationship and aggregation represents is a relationship.Here room object contain the chair object.That means, if you delete lineitem, then the associated product can exist.Both the classes represent two separate entities.An aggregation is a special form of association.
Consider a situation, employee object contains many informations such as id, name, emailid etc.For instance, a car object is an aggregation of an engine, seat, wheels, and other objects.In a composition relationship, objects cannot remain in the scope of a system without each other.Aggregation is implemented in the below statement.In a java class, where there lies an entity reference, it becomes aggregation.
In our example, we could use pieces of the handle class for other classes (e.g., scraper).Aggregation is the process of combining things.Let us take the example:It contains one more object named rank.