+ 3

What does aggregation means and mention it's use also?

In Java inheritance

27th Apr 2019, 3:56 AM
Charitha Sri
Charitha Sri - avatar
6 Antworten
+ 8
Edwin I have to agree with ~ swim ~. Your 2nd paragraph inaccurately defines composition as an "is-a" relationship implemented via inheritance. However, composition is actually similar to aggregation as they are both defined with the "has a" relationships and are both types of associations between objects. Aggregations relate independent entities. Ex. A Student can be related to zero or more Courses. A Course can be related to zero or more Students. A Course can exist prior to being associated with Students. Students can exist prior to associating with Courses. These relationships involve "aggregating" different entities. Next, I'll describe Composition.
27th Apr 2019, 5:18 AM
David Carroll
David Carroll - avatar
+ 8
Composition relates Class A with Class B such that Class B is dependent on Class A and cannot exist without Class A. Examples of Composition: - Student -> CourseEnrollment - Customer -> Order - Course -> Module In the above examples, the class types on the right could not exist without the class types on the left.
27th Apr 2019, 6:05 AM
David Carroll
David Carroll - avatar
+ 2
An aggregation -has-a relationship, e. g. a person has an address. You implement that by a reference from one class (Person) to another class (Address) so that Address is an attribute of Person. See: http://www.javatpoint.com/aggregation-in-java A composition is defined as an is-a relationship, e.g. a person is a programmer. That can be implemented as an inheritance (Programmer extends Person).
27th Apr 2019, 3:59 AM
Edwin
Edwin - avatar