Mar 13, 2008
The right way to look at single inheritance is as a specialization of composition. Like all specializations, it does less. It is more specific. Whenever you declare that Child IS-A Person, the compiler writes “Child HAS-A Person” and “Child BEHAVES-LIKE-A Person” and “Child DELEGATES-TO Person” for you. When this is exactly what you mean to accomplish, it is useful: it expresses your intent clearly to other programmers.

When single inheritance is not exactly what you mean to express, use the more general purpose, flexible tool: composition.

Comments gratefully appreciated. Please send them to me by any method of your choice and I'll include them here.

archive
projects
writings
videos
subscribe
Mastodon
RSS (?)
twtxt (?)
Station (?)