Beefy Boxes and Bandwidth Generously Provided by pair Networks Cowboy Neal with Hat
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

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

by Courage (Parson)
on Dec 24, 2002 at 17:25 UTC ( #222112=note: print w/ replies, xml ) Need Help??


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

Just a simple question:

Does your approach supports inheritance? multiple inheritance?
Does Abigail-II's approach supports multiple inheritance?

Thank you for good idea, it's really interesting.
Courage, the Cowardly Dog


Comment on Re: Class::InsideOut - yet another riff on inside out objects.
Re^2: Class::InsideOut - yet another riff on inside out objects.
by Aristotle (Chancellor) on Dec 24, 2002 at 17:31 UTC

    First off multiple code inheritance is supported any way you do OO in Perl.

    As far as this is concerned it is basically Abigail's approach and yes, it supports multiple data inheritance flawlessly. In contrast, that's anywhere from difficult to an outright pain with the traditional hashref based approach.

    Makeshifts last the longest.

      First off multiple code inheritance is supported any way you do OO in Perl.

      I'm being niggly - but this isn't always true. It is possible to implement OO models in perl (e.g. Class::ArrayObjects) that do not support MI.

Re^2: Class::InsideOut - yet another riff on inside out objects.
by adrianh (Chancellor) on Dec 24, 2002 at 20:31 UTC
    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...

Re^2: Class::InsideOut - yet another riff on inside out objects.
by adrianh (Chancellor) on Jan 04, 2003 at 17:33 UTC

    Looks like I lied slightly - I've just found what I think is a bug in Attribute::Handlers that can cause Class::InsideOut to fail if you have multiple inheritence and custom DESTROY methods in the subclasses.

    <sigh>

    NOTE: this has nothing to do with a problem in Abigail's technique - just the use of Attribute::Handlers to implement the field declaration.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://222112]
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-04-23 09:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (541 votes), past polls