in reply to The Accessor Heresy
The Law of Demeter is intended to encourage shy, decoupled code (Pragmatic Programmer p.138) to promote maintainability & adaptability. Without the Law of Demeter, objects depend more on the internal structure of other objects. The trade off is that you end up writing more accessor methods.
In this example, if Circle::Radius or Circle::Area were changed (or replaced by other objects) interface compatibility must be maintained, not only for Circle but for all the other code that works with Circle objects. If the Circle::Radius & Circle::Area objects are accessed through accessor methods of Circle, then their interface details are hidden from any users of the Circle class.
Of coruse, any tenet of programming if taken too far leads to horrible code.
L
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: The Accessor Heresy
by Roy Johnson (Monsignor) on Nov 28, 2005 at 21:32 UTC |