in reply to Re: "Accessors (don't always) break encapsulation"
in thread "Accessors break encapsulation"?
I assume that you are referring to some of the logging modules out there that do this (eg, Log::Log4perl). In the simple case I agree with you (and it's actually what most of them do behind the scenes anyway). But the problem occurs when you have a computationally expensive error string. For instance:if ($obj->error) { $obj->log_error; }
By using the first approach, this expensive call could be avoided if the object just gave you an accessor so that you could make the decision yourself if the logging was necessary.use Data::Dumper; $obj->log_error(Dumper($some_very_large_structure));
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: "Accessors (don't always) break encapsulation"
by Ovid (Cardinal) on Jul 19, 2005 at 17:51 UTC | |
by diotalevi (Canon) on Jul 21, 2005 at 17:20 UTC | |
|
Re^3: "Accessors (don't always) break encapsulation"
by tilly (Archbishop) on Jul 20, 2005 at 02:33 UTC |