While working on some guts of a class library I use at work, I realized that there's all sorts of inheritance types. I was wondering what others have thought on this.
  1. Functional inheritance. We all know and love @ISA.
  2. Attribute inheritance. This isn't implented directly in Perl, but people do it easily using hash properties.
  3. Value inheritance. For example, you have a class attribute that stores a key and a coderef to be called, to indicate that an attribute has some dynamic processing. (Bad implementation, I know, but I had to work within constraints.) If you inherit the attribute, you need to inherit the values populated by the parent class(es).
Primarily, I was wondering what people thought about value inheritance. I personally don't like it - there's better ways to represent the relationships. But, have other run into this?

------
We are the carpenters and bricklayers of the Information Age.

Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.

  • Comment on Inheriting different types of things...

Replies are listed 'Best First'.
Re: Inheriting different types of things...
by lachoy (Parson) on Nov 06, 2001 at 09:10 UTC
Re: Inheriting different types of things...
by princepawn (Parson) on Nov 06, 2001 at 04:40 UTC
    Damian has a few things for you:
  • Class::Delegation will make your has-a relationships more definitional
  • NEXT is a pseudo-method that allows more control over standard @ISA inheritance

    and about value inheritance, i would say you are right. Perl supports method inheritance but not data inheritance

Perhaps a better implementation
by Fletch (Bishop) on Nov 06, 2001 at 17:07 UTC

    That almost sounds like it would be better solved using the State Pattern or the Strategy Pattern. Basically you make the behavior that changes an external class hierarchy and then call the relevant method on the instance's current state or strategy instance.

Re: Inheriting different types of things...
by dragonchild (Archbishop) on Nov 06, 2001 at 19:12 UTC
    All of those suggestions do have merit. (I especially like the Patterns one!) However, I'm pretty positive that there are no modules that support value inheritance. Why? Because, as far as I know, it's a bunk way of inheriting. But, is it? Could it be useful for something?

    ------
    We are the carpenters and bricklayers of the Information Age.

    Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.