Friday, April 3, 2020

Composition and Aggregation


Whenever consider the associations, most of the programmers have lack of awareness about composition and aggregation. Perhaps, they are confused with these concepts. However before clarifying above topic, I thought to give a better picture about an association.

When we talk about the programming world, association is a relationship between two entities or among multiple entities. We can clarify this concept using a simple example. Just imagine about human body. When we consider the body, it consists with head, hands, legs, heart likewise. Then, lets come to the programming world back and take Head and Hands as an example. We can say human body should have hands. We can create two separate class to clarify this.
Class Human { List hands ; // Human functions }

Class Hand { // Hand Functions }
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
Class Human {
 List<Hand> hands ; 

 // Human functions

}


Class Hand {

 // Hand Functions

}
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
Class Human {
 List<Hand> hands ; 

 // Human functions

}


Class Hand {

 // Hand Functions

}


I have represented above real world example using two class. Then you will see we create two separate class called Human and Hand. Then Human class has a list which is holding Hand objects. This is a simple association between two relationship.

Sunday, October 13, 2019