Hmm….I appreciate the explanation.
Scott Molinari
1

> The question is, are we inheriting the class, or are we inheriting component parts to form a larger whole?

They’re the same thing. Literally. The second half of your sentence described what inheritance actually is. From the UML manual: “Inheritance allows a full description of an element to be constructed by assembling declaration fragments.”

> The goal with composition is to create has-a relationships between the objects.

And Elliott’s idea of composition fails to do that. B is-a A literally means “A’s specification implies B’s specification.” So if a stamp A has methods a(), b(), c(), and stamp B = stampit.compose(A), then B *also* has methods a(), b(), c(). Stamp A’s specification implies stamp B’s specification. Stamp B IS-A A. This isn’t HAS-A just because Elliott proclaimed it so.

> In your examples earlier, you only considered one class and then extended from it.

If you follow my “past discussion” link from one post ago, you’ll see that there’s also an example where I extend from multiple classes. That’s still not composition. That’s just multiple inheritance.

> Try creating has-a relationships with multiple classes by extending them. It simply won’t work.

It actually works extremely easily. Remember, class/extends and stampit/compose are mirror images of each other. Let’s translate one of Elliott’s “composition” examples. Here it is first in Python classes and inheritance (because Python natively supports multiple inheritance). Then here it is in C++ classes and inheritance (C++ also supports multiple inheritance). And finally here it is in JavaScript classes and inheritance (using class factories for multiple inheritance).

stampit/compose is **NOT** composition. It’s inheritance.

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.