Re: Schema Design: Composition vs Subclassing

Hi Folks,

A couple of weeks ago I raised the topic: which approach is to be
favored - design by subclassing or design by composition.  There were
numerous responses, largely in favor of subclassing.

Since that time I have gone off and done some thinking and researched
how this design issue is approached in the Object-Oriented field.  As a
result I have now convinced myself that composition should be the
favored approach (as it is in the OO field).  I have written up this
issue and posted it on the BestPracticesHomepage:

http://www.xfront.com/composition-versus-subclassing.html

Any comments on this would be appreciated.

The paper addresses most of the issues that were raised a couple of
weeks ago.  The one issue that it does not address I do so here:

> I think that design-by-subclassing has one killer advantage,
> namely that applications can use information about the type hierarchy
> in order to provide common processing for all elements of a particular
> (high level) type.

My response to this is to quote from the Design Patterns book by Gamma
et al: "Delegation is a way of making composition as powerful for reuse
as inheritance.  In delegation, two objects are involved in handling a
request: a receiving object delegates operations to its delegate.  This
is analogous to subclasses deferring requests to parent classes."  

/Roger

Received on Monday, 15 April 2002 08:37:59 UTC