InterviewSolution
| 1. |
Explain Aggregation vs Composition in Java. |
|
Answer» An association is a relationship that exists between two distinct classes and is established through their Objects. One-to-one, one-to-many, many-to-one, and many-to-many associations are all possible. An Object communicates with other Objects to leverage the capabilities and services provided by that object in Object-Oriented programming. Association has two forms and they are composition and aggregation. Aggregation is a unique type of association in which:
In the above image, we can clearly see that each teacher is associated with a college, and each student is also associated with a college. Thus, both the entities, the student and the teacher can exist independently. Composition is a type of Aggregation in which two entities are extremely reliant on one another.
In the above image, we can clearly see that both TYRE and Engine form an integral part of a vehicle. Both are reliant on each other. Without either of them, the Vehicle entity is useless. |
|