Hello Dear Reder, In this article, we are discussing what is Orientation, Association, Aggregation as well as Composition in Java Language. I will try to give some Real-world Examples which makes it easy to understand for you.
Orientation, Association, Aggregation and Composition in Java
- java sees everything around its self as an object. hance it is an object-oriented programming language.
📝Association ( Has – A Relationship ): Association is one of the concepts of Object Orientation which is also called as Has–A Relationship.
It is a process of one or many Objects getting associated with another Object.
✔There are 2 forms of Association :
I. Composition.II. Aggregation.
📝Composition: A composition is a special form of association. where an associated Object can not logically independently exists on its own without Owner Object.
- If Owner Object is destroyed. then the associated object is also destroyed. Hence it is called Strong Has – A Relationship.
Example of Composition: Plant and Leaves.
- The plant is a whole and Leaves are parts. If the plant is destroyed. then all corresponding Leaves for that Plant should be destroyed.
One More Example: Human and Heart.
📝Aggregation: An aggregation is a special form of association. where an associated Object can logically independently exist even without the Owner Object.
- If Owner Object is destroyed still an associated Object can exist. Hence it is called Weak Has – A Relationship.
Example of Aggregation: Driver and Car.
- If Driver Object is destroyed it will not affect Car Object and Vise-Versa.
Example (2): Employee and company.
Admin Words:- Hopefully, now you can understand Orientation, Association, Aggregation, and Composition. if you still confused then please remind us to comment below of this post I will try to make it more easy for you. And stay away to learn programs J with Us. and also Read our Next Program.
Recommended: -
0 Comments