Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

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.


Comment on I don't think inheritance is essential
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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://488367]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (8)
As of 2014-09-22 06:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (182 votes), past polls