The Artima Developer Community
Sponsored Link

One-sided comparison

Advertisement

Advertisement

This page contains an archived post to the Design Forum (formerly called the Flexible Java Forum) made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

One-sided comparison

Posted by Doug Bell on 21 Oct 1998, 3:27 PM

Bill,

First, before I present my critiques, let me say that your article generally does a good job of presenting an important subject that is often either missed or misunderstood by object-oriented programmers.

While I agree composition is powerful, and frequently the correct choice, I think your article presented the subject with a bias towards composition. Each technique has it's place in OO design, and composition can be misused just as easily as inheritance.

Specifically, you skewed the comparision in favor of composition in the following ways:

1) You trivialized the importance of type compatibility as a benefit of inheritance by simply saying it makes it easier to add new subclasses. I realize you will talk about this more when you discuss interfaces in your next article, but the type hierarchy is a fundamental design tool in OOD and should be given more weight in your comparison. Besides, when you use an interface, you reintroduce all the interface-fragility issues you say are a problem in inheritance--changing the interface definition breaks all the same code as changing the superclass interface.

2) While you mention that composition allows you to delay the creation of back-end objects, you fail to mention that composition-based designs generally result in the instantiation of many more objects. (This is also a performance issue in addition to the delagation overhead you mention.)

3. You neglect to talk about the maintainance cost involved with delagation methods used to get at the capabilities of the back-end class. While delegation is frequently well worth the extra effort (i.e. the use of compositing in the java.io filter classes), it actually makes maintaining the front-end classes more difficult than maintaining the equivelant subclasses. In addition, the delagation methods not only add a performance overhead (as you mention) but also increase the size of the code. Every line of code not only has to be written, but debugged and maintained as well.

Doug Bell



Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us