Notes - Aggregation PDF

Title Notes - Aggregation
Course Object Oriented Programming
Institution Universiti Tun Hussein Onn Malaysia
Pages 3
File Size 175.7 KB
File Type PDF
Total Downloads 112
Total Views 145

Summary

Download Notes - Aggregation PDF


Description

In Object Oriented Programming, there are many different types of relationships which can exist between two or more classes. The most common two types are:  

Inheritance — an “is a” relationship Association — a “has a” relationship

This blog is going to do a deep dive into the two types of Association relationships — Aggregation and Composition. What is an Association relationship? An association relationship between two classes is a “has a” relationship. For example:   

A Car has an Engine and a Wheel A Person has a Leg and an Arm A Book has Pages

This usually represents when there are two classes, ClassA and ClassB, and either:  

ClassA contains ClassB as an attribute, or Instances of ClassB are constructed inside ClassA

What’s the difference between Aggregation and Composition? There are two sub-types of Association relationships — Aggregation and Composition. What’s the difference between these two? Composition Composition implies that the contained class cannot exist independently of the container. If the container is destroyed, the child is also destroyed. Take for example a Page and a Book. The Page cannot exist without the Book, because the book is composed of Pages. If the Book is destroyed, the Page is also destroyed. Aggregation With an aggregation, the child can exist independently of the parent. So thinking of a Car and an Engine, the Engine doesn’t need to be destroyed when the Car is destroyed.

How are these represented a UML diagram? In a UML diagram, both Aggregation and Composition are represented with a diamond arrow between the classes. The diamond end goes on the side of the container.  

Aggregation uses an open diamond Composition uses a closed diamond

Figure 1

Figure 2...


Similar Free PDFs
Notes
  • 18 Pages
Notes
  • 12 Pages
Notes
  • 61 Pages
Notes
  • 35 Pages
Notes
  • 19 Pages
Notes
  • 70 Pages
Notes
  • 6 Pages
Notes
  • 35 Pages
Notes
  • 29 Pages
Notes
  • 70 Pages
Notes
  • 6 Pages
Notes
  • 19 Pages