$self->{attribute} becomes $attribute{$self}

Minor nit: it should be $attribute{ refaddr $self }. Just plain $self will break if stringification is overloaded.

Inside-out objects also provide data protection.

As I see it, encapsulation is not synonymous with data protection. Encapsulation means providing a set interface for interaction such that other parts of the program do not need to take into account the internal implementation of the object. Regular Perl objects can only provide incomplete encapsulation, even with interface methods, because subclasses must use the same underlying data structure. If the parent class changes its implementation, the subclass will break. That's an encapsulation failure.

Inside-out objects can provide complete encapsulation, but this is only true if the memory address is used directly as the index into the property data structures. Inside-out objects that cache an identifier or memory address inside a blessed scalar (as Class::Std does, for example) are also mandating a data structure and thus fail to completely encapsulate the implementation.

-xdg

Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.


In reply to Re^2: OO - inside-out or by means of a anonymous sub? by xdg
in thread OO - inside-out or by means of a anonymous sub? by gargle

Title:
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, details, 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, summary, 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.