"Inside out objects" do not prevent direct access to the attribute data within the class!
While I think that the AM missed the point Andy was making they are correct on the inside out object front. You can use inside out objects to prevent a class from having global access to attribute data. For example:
package MyClass;
{
# we make an attribute hash private to the foo method
my %foo;
sub foo {
my $self = shift;
$foo{$self} = shift if @_;
return $foo{$self};
};
};
sub bar {
my $self = shift;
# so we can only access %foo using method foo here
print $self->foo;
};
However, regardless of whether you implement your accessors with inside out objects or normal blessed hashes, Andy's point about being consistant with your use of accessors is a very good rule of thumb. It's certainly my policy.
If you need to make your attribute setters/getters public (and that's often a big "if" as others have pointed out) then using them consistantly is a good idea for all the reasons Andy mentioned in the OP.
Of course with a sane language design like Eiffel (or, I think, Perl 6 ;-) the syntax for attribute access and method calls is identical so the whole issue just disappears. |