in reply to Re: regex transforms of object attributes
in thread regex transforms of object attributes
Nice tested code:)
The problem with doing it that way is that you build a dependancy upon the implementation of the class. You have to know that the class is based upon a hash and that the data return by the $obj->content(); method is stored in the hash under the key name 'content'.
If the implementation of the class changes for some reason, then it will require modification to every calling app also. That's what is meant by 'breaking encapsulation' or 'tight coupling'.
Eg. If the class called by your test code was implemented this way, it will break your test.
package Test; my %contents; sub new{ my( $class, $value ) = @_; my $self = bless \rand, $class; $contents{ $self } = $value; return $self; } sub content : lvalue { my( $self ) = shift; $contents{ $self }; } 1;
Of course, if the content has to be verified then using an lvalue sub will also break, but that a different argument entirely:)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: regex transforms of object attributes
by Plankton (Vicar) on Jun 19, 2004 at 01:47 UTC |