Compare the Difference Between Similar Terms

Difference Between

Home / Technology / IT / Programming /Difference Between Aggregation and Composition

Difference Between Aggregation and Composition

January 19, 2018Posted byLithmee

Key Difference – Aggregation vs Composition

Object-Oriented Programming (OOP) is a common paradigm in software development. Theobjectis an instance of a class. It is not possible to create objects at once. There should be a blueprint or a description to create an object. That blueprint is known as a class. Aclasscontains properties and methods. Objects are created using classes. Class and object are similar to a plan and house in the real world. It is not possible to build a house without a proper plan. Likewise, a class is used to create an object. An object collaborates with other objects. A link with represents the relationship of two or more objects is called as an “association”. Aggregation and composition are types of associations. They describe the relationship among classes. This article discusses the difference between aggregation and composition. Thekey difference聚合和组合之间aggregation is an association between two objects that describes the “has a” relationship and composition is a more specific type of aggregation that implies ownership.

CONTENTS

1.Overview and Key Difference
2.我s Aggregation
3.我s Composition
4.Similarities Between Aggregation and Composition
5.Side by Side Comparison – Aggregation vs Composition in Tabular Form
6.Summary

我s Aggregation?

A relationship between two objects is shown by drawing a line in Unified Modelling Language (UML). The link is an association. UML helps to get a visual representation of the system. It is different than regular programming languages. Association also defines the multiplicity of objects. They are one-to-one, one-to-many and many-to-many. When a single object of class A is associated with the single object of class B, that is a one-to-one relationship. An example is an author writing a book. In that example, one author is writing a book.

When one object of class A is associated with many objects of class B, it is a one-to-many relationship. An example is, a department can have many employees. When the object of class A is associated with many objects of class B and an object of class B is associated with many objects of class A, it is a many-to-many association. One example is, an employee can work on multiple projects and a project can have multiple employees.

Aggregation is type association that further describe the relationship between objects. Aggregation describes “has a” relationship. Some examples that describe the relationship are, a student “has a” student id, a vehicle “has an” engine. It is also possible to expand a large quantity with the relationship. Some examples are, a bank “has many” bank accounts, a class “has many” students. It can be explained using the below example.

Difference Between Aggregation and Composition

Figure 01: Aggregation

According to the above example, the classroom consists of a student or many students. Multiplicity is also used to indicate the number of objects. It describes that one classroom has multiple students. The symbol of the diamond represents the aggregation in UML. Student objects do not rely on the class object. If the class object is destroyed, it won’t affect the student objects. Those objects will still exist.

我s Composition?

The composition is a more specific form of aggregation. It describes the ownership. It can be explained using the below example.

Key Difference Between Aggregation and Composition

Figure 02: Composition

According to the above, the book object consists of page object or pages. Multiplicity is also used to indicate the number of objects. It describes that one classroom has multiple students. The symbol of diamond that is highlighted represents the composition in UML. As the book has a page or many pages, it is an aggregation, but it is more specified. If the book object is destroyed, then the page objects also get destroyed. Page objects cannot exist without the book object. Therefore, the composition is a more specific form of an aggregation that implies ownership.

What are the Similarities Between Aggregation and Composition?

  • Both are used in Object Oriented Programming.
  • Both are used in Unified Modeling Language (UML) to get a visual understanding of the system.

我s the Difference Between Aggregation and Composition?

Aggregation vs Composition

Aggregation is an association between two objects which describes the “has a” relationship. The composition is the most specific type of aggregation that implies ownership.
UML Symbol
Aggregation is denoted by a diamond. Composition is denoted by a highlighted diamond.
Functionality
In aggregation, if the owning object destroyed, it will not affect the containing object. 在作文中,如果拥有对象销毁,will affect the containing object.

Summary –Aggregation vs Composition

Object-Oriented Programming is a major paradigm in software development. In OOP, the system is modeled using objects. These objects do not exist in isolation. Objects collaborate with other objects. The relationship among objects is known as association. Aggregation and composition are types of association. The difference between aggregation and composition is that aggregation is an association between two objects which describes the “has a” relationship and composition is the more specific type of aggregation that implies ownership. Aggregation and composition both help to understand the behaviour of the system.

Download the PDF Version of Aggregation vs Composition

You can download PDF version of this article and use it for offline purposes as per citation note. Please download PDF version hereDifference Between Aggregation and Composition

Reference:

1. Using aggregation and composition, People career, 22 May 2015.Available here

Related posts:

Difference Between Association and AggregationDifference Between Association and Aggregation Difference Between Inheritance and Composition Difference Between Directed and Undirected Graph Difference Between Drama and Play Difference Between printf and fprintfDifference Between printf and fprintf

Filed Under:ProgrammingTagged With:Aggregation,Aggregation and Composition Differences,Aggregation and Composition Similarities,aggregation definition,Aggregation Function,Aggregation Symbol,Aggregation vs Composition,Compare Aggregation and Composition,Composition,Composition Definition,Composition Function,Composition Symbol

About the Author:Lithmee

Lithmee Mandula is a BEng (Hons) graduate in Computer Systems Engineering. She is currently pursuing a Master’s Degree in Computer Science. Her areas of interests in writing and research include programming, data science, and computer systems.

Leave a ReplyCancel reply

Your email address will not be published.Required fields are marked*

Request Article

Featured Posts

Difference Between Coronavirus and Cold Symptoms

Difference Between Coronavirus and Cold Symptoms

Difference Between Coronavirus and SARS

Difference Between Coronavirus and SARS

Difference Between Coronavirus and Influenza

Difference Between Coronavirus and Influenza

Difference Between Coronavirus and Covid 19

Difference Between Coronavirus and Covid 19

You May Like

Difference Between Symplast and Vacuolar Pathway

Difference Between Symplast and Vacuolar Pathway

Difference Between Nifty and Sensex

Difference Between Magistrates Court and Crown Court

Difference Between Clementine and Tangerine

Difference Between OAU and AU

Latest Posts

  • 我s the Difference Between Collagen and Keratin
  • 我s the Difference Between Krypton and Argon
  • 我s the Difference Between Mercury Cell and Diaphragm Cell
  • 我s the Difference Between Inflammation and Allergy
  • 我s the Difference Between UV Vis and Fluorescence Spectroscopy
  • 我s the Difference Between Amyl Alcohol and Isoamyl Alcohol
  • Home
  • Vacancies
  • About
  • Request Article
  • Contact Us

Copyright © 2010-2018Difference Between. All rights reserved.Terms of Useand Privacy Policy:Legal.