Associations(Composition and Aggregation) or has-A Relationship in Java.

Has-A Relationship is also known as Composition and Aggregation in java.

Composition: Without an existing container object if there is no chance of the existing contained object, then container and contained objects are strongly associated, and this strong association is known as Composition.

Example: University consists of several departments, without existing University there is no chance of existing department, hence University and Department are strongly associated.

Aggregation: Without an existing container object if there is a chance of the existing contained object, then container and contained objects are weakly associated, and this weak association is known as Aggregation.

Example: Department consists of several Professors, without the existing Department there may be a chance of existing Professors Objects, hence Department and Professors are weakly associated.

Below is the implementation of both the concepts discussed above.

OOPS Concepts in Java
/*This is the code for Association topic from Java or has-a relationship
* if University doesn't exist then Department will also not exist --> Strong Association or Composition
* but if University doesn't exist then also the Professors will exist--> Weak Association or Aggregation*/

Thank you for reading.

Software Developer