From the course: Programming Foundations: Object-Oriented Design
Unlock the full course today
Join today to access over 24,800 courses taught by industry experts.
Composition - Python Tutorial
From the course: Programming Foundations: Object-Oriented Design
Composition
- A more specific form of aggregation is something called composition. Like aggregation, composition is based around a has-a relationship between objects but it specifically implies ownership. I might say that a spaceship has an engine, but more accurately, I should that the spaceship owns the engine. Composition implies ownership and an engine has no meaning or purpose in the system without a spaceship. - It's like attaching the object to one of these model ships. The spaceship has a shield and, since it's a star fighter, it has a weapon. Or I should say, it owns a weapon. - Right. The space ship is composed of several different objects that each have their own attributes and behaviors. But a key difference between composition and aggregation is that in a composition situation, if the owning object is destroyed by, say, an asteroid ... - Or an Olivia. - The contained objects are destroyed, too. The ships engine…
Contents
-
-
-
-
-
-
-
-
(Locked)
Identifying inheritance situations4m 55s
-
(Locked)
Using inheritance2m 44s
-
(Locked)
Abstract and concrete classes3m 10s
-
(Locked)
Interfaces4m 15s
-
(Locked)
Aggregation2m 3s
-
(Locked)
Composition1m 45s
-
(Locked)
Challenge: Jukebox class relationships1m 6s
-
(Locked)
Solution: Jukebox class relationships3m 17s
-
(Locked)
-
-
-