I agree (or if I am under 13 my parent or guardian agrees on my behalf) to the terms and conditions of use and that: - My test statistics may be published on the site leaderboard against my username - My teacher(s) can review my test scores - I can receive feedback on my tests from my teacher(s)
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
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?
Definition and example
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 ofPages. If the Book is destroyed, the Page is also destroyed. In code, this usually refers to the child instance being created inside the container class:
page1 = Page('This is content for page 1')
page2 = Page('This is content for page 2')
self.pages = [page1, page2]
def __init__(self, content):
self.content = contentbook = Book() # If I destroy this Book instance,
# the Page instances are also destroyed