in reply to Real live usage of inheritance?

So my question is, when/what have you actually used inheritance (for) in a 'real' project?
Indeed, many times. I've used it to determine standard data access behaviour across classes, to inherit from a base object defintion and generally adding structure to classes (e.g fielding out utility methods to a utility module so as to not clutter up the basic class definition). Perhaps the most obvious use is laziness - why bother maintaining X methods across Y classes, when you can just have your subclasses inherit from your main class and maintain the non-overriden methods there (and as you can probably guess, laziness isn't the only benefit).
HTH

_________
broquaint

Replies are listed 'Best First'.
Re: Re: Real live usage of inheritance?
by hardburn (Abbot) on Nov 05, 2003 at 20:28 UTC

    Perhaps the most obvious use is laziness - why bother maintaining X methods across Y classes, when you can just have your subclasses inherit from your main class and maintain the non-overriden methods there . . .

    Eek! Such is really false-laziness, as it tends to break object relationships into whatever the programmer felt like at the time, instad of a logical flow. It tends to make things a lot harder over time, since two classes that really have nothing to do with each other are suddenly in a parent-child relationship, just because there was a bit of code in the parent that was also needed in the child.

    Down that path lies many a broken OO project.

    ----
    I wanted to explore how Perl's closures can be manipulated, and ended up creating an object system by accident.
    -- Schemer

    : () { :|:& };:

    Note: All code is untested, unless otherwise stated

      Eek! Such is really false-laziness ... since two classes that really have nothing to do with each other are suddenly in a parent-child relationship
      Er ... perhaps. But I meant to imply without inheritence, it's rather more difficult to maintain related modules, not to inherit just because of a common method. So in conclusion, inheritence is powerful, but has its dangers, like most useful programming constructs.
      HTH

      _________
      broquaint