Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re^2: Class::InsideOut - yet another riff on inside out objects.

by adrianh (Chancellor)
on Dec 24, 2002 at 20:31 UTC ( #222134=note: print w/ replies, xml ) Need Help??


in reply to Re: Class::InsideOut - yet another riff on inside out objects.
in thread Class::InsideOut - yet another riff on inside out objects.

Does your approach supports inheritance? multiple inheritance?

Yes and yes. For example:

use strict; use warnings; use Class::InsideOut::Accessor; { package Square; use base qw(Class::InsideOut); my (%x, %y, %size) : Field; sub new { bless [], shift }; }; { package Coloured; use base qw(Class::InsideOut); my %colour : Field; }; { package ColourSquare; use base qw(Square Coloured); }; my $o = ColourSquare->new; $o->x(10); $o->y(12); $o->size(6); $o->colour("red"); print "the colour is ", $o->colour;
Does Abigail-II's approach supports multiple inheritance?

Yes (and my method is Abigail-II's method with some syntactic sugar and a different DESTROY mechanism).

The advantage of doing it this way is that some kinds of problems caused by the traditional hash mechanism disappear because it is guaranteed that there is no sharing of attributes between classes.

One of the problems of using a traditional hash is that if two different classes use the same hash key to index an attribute then you cannot directly inherit from both of them (because they try and use the same bit of the hash for different purposes). You can use things like Class::Delegation to get around this problem, but it is more work - and tracking down the bug can take time.

Of course, all this depends on what you mean by multiple inheritance! Some languages (e.g. Eiffel) have a far more flexible approach to MI than languages like C++, Java & Perl.

For example, Class::InsideOut doesn't support inheriting from a class multiple times and having multiple copies of the attribute. But this isn't supported in the perl hash-style object implementation either.

If you're interested in multiple inheritance I would spend some time introducing yourself to inheritance in Eiffel (this page has some pointers) which is the most comprehensive model of MI I've come across in any language. It's quite hard to do some things in perl that are trivial in Eiffel.... Hmmm... might be worth a meditation at some later date...


Comment on Re^2: Class::InsideOut - yet another riff on inside out objects.
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (14)
As of 2014-07-14 14:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (261 votes), past polls