$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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |