Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

I don't think inheritance is essential

by systems (Pilgrim)
on Sep 01, 2005 at 13:17 UTC ( #488367=note: print w/replies, xml ) Need Help??

in reply to Re: Judge a book by it's author
in thread Advanced Perl Programming, 2nd edition

First not all object systems implement or provide inheritance for example check snit
In my understanding inheritence serve two purposes
  1. Gives you a mean to say that an object have more than one type (play more than one role, thus inheritance and multiple inheritance), this is only useful if you ever need to test an object type, which as far as I only required by static languages, and usually forwned upon in dynamic languages
  2. Give a default value for the method the object inherited (unless you are inheriting from an abstract class)
I think you find can other ways to achive both requirements without inheritance. Which makes inheritance an implementation detail, a technique not a requirement.
I prefer to focus on the requirement, and consider the different ways and alternatives to achieve it.

Replies are listed 'Best First'.
Re: I don't think inheritance is essential
by robot_tourist (Hermit) on Sep 01, 2005 at 14:48 UTC

    IMO your point number two is pretty fundamental to object orientation and is a very good one-line synopsis, you take a class and extend it by adding functionality, but keeping all the stuff you don't want to re-invent. And it gives you a nice tree to draw when you are designing your system.

    Personally, I can't think of a good reason not to use inheritance.

    How can you feel when you're made of steel? I am made of steel. I am the Robot Tourist.
    Robot Tourist, by Ten Benson

      Personally, I can't think of a good reason not to use inheritance.

      I can. It encourages code reuse along the wrong lines, caring more about position in an arbitrary (and quite possibly wrong hierarchy) than about the capabilities of the class.

      That's why Perl 6 encourages the use of roles.

        Yes, multiple inheritance is quite lame for mixin style programming, but try to think a bit more abstract.
        The important part is that we use it in combination with NEXT for AOP like programming, think AspectJ without static trigger points!
        package Foo; use base qw/Bar::Unicode Bar/; __PACKAGE__->prepare_parameters; package Bar; sub prepare_parameters { my $class = shift; # initialize parameters... } package Bar::Unicode; use NEXT; sub prepare_parameters { my $class = shift; # let parent initialize parameters $class->NEXT::prepare_parameters; # utf8 encode parameters... }
        Hope this makes it a bit clearer.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://488367]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (4)
As of 2018-05-24 01:35 GMT
Find Nodes?
    Voting Booth?