- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Association, Composition and Aggregation in Java
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.
Example of Composition
//Car must have Engine public class Car { //engine is a mandatory part of the car private final Engine engine; public Car () { engine = new Engine(); } } //Engine Object class Engine {}
Example of Aggregation
//Team public class Team { //players can be 0 or more private List players; public Car () { players = new ArrayList(); } } //Player Object class Player {}
- Related Articles
- Association, Composition and Aggregation in C#
- Difference between Association and Aggregation in Java
- Difference Between Aggregation and Association
- Difference between composition and aggregation
- Difference Between Aggregation and Composition
- Composition vs Aggregation in C#
- What are the difference between Composition and Aggregation in C#?
- Aggregation in Java
- Difference between inheritance and composition in Java
- What is aggregation in Java?
- Why use aggregation in Java?
- What is a composition in Java?
- Difference Between Link and Association
- MongoDB aggregation and projection?
- American Psychological Association and Ethical Codes
