Syntactic Confectionery Delight | |
PerlMonks |
Re^4: Law of Demeter and Class::DBIby jplindstrom (Monsignor) |
on Nov 19, 2004 at 22:09 UTC ( [id://409171]=note: print w/replies, xml ) | Need Help?? |
I agree that accessing the underlying hash is a bad idea, but that's not the point. Among other things, OO is about putting the logic near the data.
Let's say we want to indicate that a logger object should flush itself to disk when it's appropriate (it may take some time, so we can't do it right away). An example of not so good OO design:
It's bad OO design to use getters to read the state of an object and then use that information to make decisions about how to use the object. The logic controlling the object is now located outside of the object rather than inside it. So you avoid the getters (asking the object what state it has) and instead tell the object what you want it to do and it can sort out how to do that itself.
and the logic controlling whether to flush the log data to disk is now implemented in the flushPending() method. Inside the object, not outside. See also: TellDontAsk /J
In Section
Meditations
|
|