Before proceeding I'd like to share one of the possible situations that you may encounter in your daily need or maybe in an interview. Let's dive into it in a practical way.
The question is, "What is the difference between composition and aggregation?" In this article I'll provide my understanding of composition and aggregation.
The following image is fictional and it may be one of the possible scenarios with warrior's fight.
Aggregation
Aggregation means “The act of gathering something together”.
As inheritance gives us an "is-a" and composition gives us a "part-of" whereas aggregation gives us a "has-a" relationship.
For example, a mobile “has an” operating system. Aggregation doesn't manage the lifetime of other objects. For an example, mobile uses (has-an) operating system that may be of a different service provider. like Android, iOS and Windows. Here Aggregation theory says that a mobile has an operating system of a specific service provider.
Aggregation diagram is shown as a UML diagram with unfilled diamond notation as depicted below:
The preceding diagram states that a Mobile class may utilize an operating system from a different service provider. A mobile is not directly dependent on an operating system class. Both are independent entities. For example a Samsung is a mobile provider whereas an Android is a Google Product.
A code snippet shown below that is an OperatingSys object is injecting into the Mobile class at the constructor level. The creation of the OperatingSys class is entirely independent from Mobile Creation. Kindly have a look at the code segment as shown below:
Join the conversation! Your thoughts help the community grow.
Sign in to leave a comment
It is the same account you read, post and publish with — and you will come straight back to this page.



Yashwanth MuthineniPosted Aug 19, 2015, 6:21 AM
Nice Share
Shakti SaxenaPosted Aug 19, 2015, 5:34 AM
informative...
Santhakumar MunuswamyPosted Aug 18, 2015, 2:27 PM
Good one
Shridhar SharmaPosted Aug 18, 2015, 1:30 PM
informative. :)
Sachin KaliaPosted Aug 18, 2015, 11:06 AM
Thanks all for reading and giving valuable feedback..
Chervine BhiwooPosted Aug 18, 2015, 11:01 AM
Nice!
Sibeesh VenuPosted Aug 18, 2015, 8:16 AM
Nice Share
Rahul PrajapatPosted Aug 18, 2015, 8:03 AM
Thanks for sharing sir..
Eric HoogeveenPosted Aug 18, 2015, 7:27 AM
Thanks for the great article
RakeshPosted Aug 18, 2015, 3:23 AM
Good one
Gowtham KPosted Aug 18, 2015, 3:18 AM
Good one, Thanks for sharing
Nilesh JadavPosted Aug 18, 2015, 2:47 AM
Nice share sir :)
Vaikesh K PPosted Aug 18, 2015, 2:08 AM
Nice
Rajeesh MenothPosted Aug 18, 2015, 12:34 AM
Good One