in reply to Re: Encapsulation without methods
in thread Encapsulation without methods
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
Something to consider.$foo->setval($val) or $foo->setval($alternative); # and something like eval { $foo->val = $val } $@ and $foo->val = $alternative;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Encapsulation without methods
by Plankton (Vicar) on Jun 23, 2004 at 07:03 UTC |