in reply to Re: Encapsulation without methods
in thread Encapsulation without methods

It appears that several of us (you, Juerd, and I) have arrived at similar solutions to similar problems. It seems to me that Attribute::Property is the way to go, but I'll have to play with it more. I can't immediately tell whether it solves the "what if you change the implementation" challenge. I'm pretty sure your method does not.

My intent was to address the changing-implementation issue. I am pointing out that, initially, you can use an ordinary scalar (not even tied!) if that is how your API "should" work. Later, if the implementation changes (e.g., the member needs to be stored in and retrieved from a database), you can tie it within your module, and the API doesn't change. It's a significant point that I am not advocating tie-ing every member. Only those that need to be tied.

For validation, I think that having a set method that indicates success can be preferable to relying on error generation, depending on how reasonable you think it is for the programmer to know whether he's trying to set an illegal value. It's the difference between

$foo->setval($val) or $foo->setval($alternative); # and something like eval { $foo->val = $val } $@ and $foo->val = $alternative;
Something to consider.

We're not really tightening our belts, it just feels that way because we're getting fatter.

Replies are listed 'Best First'.
Re^3: Encapsulation without methods
by Plankton (Vicar) on Jun 23, 2004 at 07:03 UTC
    I am not too concerned about encapusaltion so much. I wish that there was a Tie::File::Object package. You know ... something worked like Tie::File does on arrays. Something that would make it easy for me to solve problems like I describe in Should I be using tie for this?.

    Plankton: 1% Evil, 99% Hot Gas.