+ 2

Association are of two type 1.Aggregation and 2.Composition

can anyone help me to understand this

2nd Apr 2018, 10:43 AM
Arun Tomar
Arun Tomar - avatar
11 Antworten
+ 4
Let's take 2 examples: 1) A lecture has students. 2) A building has rooms 1) is an aggregation. There can be multiple lectures which can be visited by a single student. 2) is a composition. One specific room can't be in 2 buildings. Aggregations don't have an ownership. The single elements can be present individually. You can kick a student out of a lecture without affecting the lecture or the other students. Elements of compositions on the other hand can't have an independent existence. A build must have at least 1 room, and a room must be in exactly 1 building.
2nd Apr 2018, 11:39 AM
Alex
Alex - avatar
+ 2
You can see the examples as objects. 1) An object of class Lecture contains * instances of students. There can be multiple lecture objects and one object of student can be in different instances of lecture. If you destruct a student the lecture can continue. If you destruct a lecture the students can still be in other lectures. 2) There is a single object of class building and it contains 1 or more objects of class rooms. If you destruct the building you need to destruct all rooms in that building. But you can destruct rooms as long as there is 1 room left in the building. (I hope here is no structural engineer around who reads this :D) If I would know what exactly you don't understand it would be easier for me to explain.
2nd Apr 2018, 2:31 PM
Alex
Alex - avatar
+ 2
Don't get me wrong it's absolutely ok to ask questions. Sometimes it's just way faster to Google it. I guess the explanation of the article I sent is exactly what you were searching, am I right?
3rd Apr 2018, 8:12 AM
Alex
Alex - avatar
+ 1
sorry i can not understand . how its related to object of the class
2nd Apr 2018, 2:13 PM
Arun Tomar
Arun Tomar - avatar
+ 1
can u pls... explain it more clearly. i really appreciate for that
2nd Apr 2018, 2:14 PM
Arun Tomar
Arun Tomar - avatar
+ 1
Thanks Alex.. and I really appreciate for your kind hard work.. Can u also explain me this also ----> What is different b/w "this" variable and "this()" function ??? can anyone help me to understand
2nd Apr 2018, 5:20 PM
Arun Tomar
Arun Tomar - avatar
+ 1
Alex according to you what u explain me... i try to explain him.. but he say Alex. for eq--> i tell u the word he used... here i go there are only two way to acces one class to another class.. 1.Association. 2.Inheritance. Association means by object..... class A { public static void main(String....b){ A a=new A();//called association; A a;//called Aggregation; new A();//called Composition; } }
3rd Apr 2018, 6:17 AM
Arun Tomar
Arun Tomar - avatar
+ 1
Who is "he"? ^^ However: A composition is a special case of an aggregation. And an aggregation is a special case of an association. Both, composition and aggregation, are associations. Since I don't feel like I am good enough at Java to give you a good implementation I just give give a link where it is explained in detail: https://www.geeksforgeeks.org/association-composition-aggregation-java/ I hope this helps. btw: a Google search with just the 3 words "Java aggregation composition" has this link as the 1st result. No offense, but you should be able to Google this kind of stuff. You will get your answers way faster + most times it's more detailed and with a lower risk of wrong informations than a Q&A post (because it's often written by proffessionals and also edited multiple times)
3rd Apr 2018, 7:47 AM
Alex
Alex - avatar
+ 1
thanks so much.. and.. I keep it mind..
3rd Apr 2018, 8:05 AM
Arun Tomar
Arun Tomar - avatar
+ 1
yes
3rd Apr 2018, 8:13 AM
Arun Tomar
Arun Tomar - avatar
0
my teacher i did.. i not get a clear idea.. what why i discuss there
3rd Apr 2018, 8:01 AM
Arun Tomar
Arun Tomar - avatar