http://www.perlmonks.org?node_id=222134


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...