Association Vs Aggregation Vs Composition with JAVA

by - October 25, 2017

I found some great website to understand that.


with nice code
Association, Composition and Aggregation in Java

with detailed description
Understanding Association, Aggregation, and Composition


- simplest one
Association Vs Aggregation Vs Composition


In short,

1. Association

  1.1. Association is a relation between two separate classes.
  1.2. Composition and Aggregation are the two forms of association.
  1.3. Association can be one-to-one, one-to-many, many-to-one, many-to-many.
                       Association in Java
                            pic1. one-to-many association

2. Aggregation 

  2.1. it represents Has-A relationship
  2.2. Each class can have different life cycles.

                        Aggregation_1
                           pic2. Aggregation

3. Composition

  3.1. it represents Part-of relationship
  3.2. Each class has same life cycles.



cf)

Aggregation vs Composition

  1. Dependency: Aggregation implies a relationship where the child can exist independently of the parent. For example, Bank and Employee, delete the Bank and the Employee still exist. whereas Composition implies a relationship where the child cannot exist independent of the parent. Example: Human and heart, heart don’t exist separate to a Human
  2. Type of Relationship: Aggregation relation is “has-a” and composition is “part-of” relation.
  3. Type of association: Composition is a strong Association whereas Aggregation is a weak Assocation.

You May Also Like

0 comments