Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
You just hit the problem with inheritance - you're extending the class, which means you're tied to its implementation details.
With traditional, hash-based objects, you are right. And that's true for most of the implementations based on a Class::* module of CPAN, including Class::Std as well. And even the new inside out based class being promoted here on Perlmonks last week.

But the pure, not on a module depending, inside-out technique deals with inheritance perfectly. It can inherit from any implementation - and if inherited from, the inheritee can use whatever implementation it wants as well. Of course, if A inherits from B, B inherits from C, and B is using an inside-out technique, but A and C don't, C might still dictate how A is implemented.

#!/usr/bin/perl use strict; use warnings; package HashBased; sub new { my $class = shift; return bless {@_}, $class; } sub noise { my $self = shift; printf "The %s goes %s!\n", $self->{name}, $self->{sound} } sub name { my $self = shift; return $self->{name}; } package InsideOut; { use Scalar::Util 'refaddr'; my %legs; our @ISA = 'HashBased'; sub new { my $class = shift; my $legs = pop; my $obj = bless $class->SUPER::new(@_), $class; $legs{refaddr $obj} = $legs; return $obj; } sub show_legs { my $self = shift; printf "The %s has %d legs\n", $self->name, $legs{refaddr $sel +f}; } sub DESTROY { my $self = shift; delete $legs{$self} } } package main; my $dog = InsideOut->new(name => 'dog', sound => 'bark', 4); my $bird = InsideOut->new(name => 'bird', sound => 'peep', 2); $dog->noise; $dog->show_legs; $bird->noise; $bird->show_legs; __END__ The dog goes bark! The dog has 4 legs The bird goes peep! The bird has 2 legs
As you can see, the super class is using hash-based objects. But that doesn't prevent an inside-out based class to inherit from it. And you could even inherit from that class and use a hash-based implementation if you want to do so.
Perl --((8:>*

In reply to Re^2: How to use Inheritance with Inside-Out Classes and Hash Based Classes by Perl Mouse
in thread How to use Inheritance with Inside-Out Classes and Hash Based Classes by ghenry

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and snow settles gently...

    How do I use this? | Other CB clients
    Other Users?
    Others contemplating the Monastery: (7)
    As of 2018-05-21 10:53 GMT
    Find Nodes?
      Voting Booth?