Agile Zone is brought to you in partnership with:

Kevin Rutherford, PhD, is a UK-based extreme programmer and agile software coach with over 30 years professional experience. He developed the Reek code-smell detector for Ruby and co-authored "Refactoring in Ruby". Kevin is a DZone MVB and is not an employee of DZone and has posted 12 posts at DZone. You can read more from them at their website. View Full User Profile

Don't Inherit Code

01.23.2013
| 2661 views |
  • submit to reddit
I learned a long time ago that there are essentially three different kinds of relationship between two classes. They are, in order of increasing tightness:

  1. Uses, in which I care only about your public API;
  2. Creates, in which I also need to know your class;
  3. Inherits/extends, in which I can also see some of your workings and I become part of you.

Don’t do that last one. Ever.

Many of the GoF patterns help move code up this list, from tight towards loose coupling. Except TemplateMethod, which not only encourages inheritance, it also creates a circular dependency by having the superclass only “work” in the presence of extensions. Bad.

Don’t inherit code. Bad.

Published at DZone with permission of Kevin Rutherford, author and DZone MVB. (source)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)

Comments

Euwe Max replied on Wed, 2013/01/23 - 4:23pm

Um... why not?

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.