From the course: Programming Foundations: Object-Oriented Design

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Composition

Composition - Python Tutorial

From the course: Programming Foundations: Object-Oriented Design

Start my 1-month free trial

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, its shield, its weapons, those are all gone. Now, although aggregation…

Contents