Copyright

Aggregation vs. Composition

Instructor: David Gloag

David has over 40 years of industry experience in software development and information technology and a bachelor of computer science

In the computer world, objects and object technologies are important concepts. In this lesson, we'll take a look at the terms aggregation and composition, what they are, and the difference between them.

Simplify to Explain

We live in a world that is so fundamentally complex, we need to simplify it in order to understand it. We talk about our vehicles when we really mean the collection of thousands of mechanical parts that move us from point A to point B. We refer to our televisions when we really mean a collection of hundreds of electronic parts that display information to us. And we remark about wildlife when we really mean the many organisms that exist in nature. The act of grouping these things together reduces the complexity, and allows us to think of them in simpler terms. The same holds true for computer science. There is a need to gather things together, and describe them as a unit. The formal terms for this process are aggregation and composition.

What is Aggregation?

Aggregation is the process of gathering objects or items together, with the purpose of referring to them as a unit. Think of the process like gathering together a set of objects that make up a class in a computer language like C++, C#, or Java. As an example, consider a class that consists of employees. We can refer to them as a whole, employees, and we can also refer to a specific instance, Jane Doe. It is important to note that the instance has all of the characteristics of the class. But, it is unique and can function on its own. Each instance has that ability. However, it still represents the class as a whole.

What is Composition?

Like aggregation, composition is a process of gathering a set of somethings together, with the purpose of referring to them as a unit. We can also think of it like a class in C++, C#, or Java. But this time, we need to look at the characteristics of the class. Let's use the employee example again. Instead of looking at an instance of an employee, like Jane Doe, we need to look at the components of the instance. For example, Jane Doe has a name, an address, a job title, and so on, plus some actions to manipulate them. In other words, a set of characteristics and operations that we group together to describe the object Jane Doe.

To unlock this lesson you must be a Study.com Member.
Create your account

Register to view this lesson

Are you a student or a teacher?

Unlock Your Education

See for yourself why 30 million people use Study.com

Become a Study.com member and start learning now.
Become a Member  Back
What teachers are saying about Study.com
Try it risk-free for 30 days

Earning College Credit

Did you know… We have over 200 college courses that prepare you to earn credit by exam that is accepted by over 1,500 colleges and universities. You can test out of the first two years of college and save thousands off your degree. Anyone can earn credit-by-exam regardless of age or education level.

To learn more, visit our Earning Credit Page

Transferring credit to the school of your choice

Not sure what college you want to attend yet? Study.com has thousands of articles about every imaginable degree, area of study and career path that can help you find the school that's right for you.

Create an account to start this course today
Try it risk-free for 30 days!
Create an account
Support