Law of Demeter

Law of Demeter
Introducing Demeter and its Laws

The degree of obeying Law of Demeter in a software application’s design affects its maintenance.
I am wondering whether the same Law or a similar one applies to the number of places one must consult in source code to understand something.

For example, if you define in C++ a macro which expands into a template, expanding in turn to a class which inherits from two classes and has a virtual function – how many source code files do you have to consult to understand what exactly is going on in the original macro expansion.

Or, a simpler case: you #define a macro which expands into a curried function call.
You #define another macro, which curries a further argument in that function call.
Then you’ll have to consult three different places in source code in order to understand the function call.

There seems to be a trade-off between maintenance needs (ability to modify the software by editing at one place and easily grepping the entire source code base to rule out any special cases), and understanding needs (ability to understand everything about a variable or function by referring to its definition/s at only one place; possibly not having to grep for more than one pattern in order to match all uses of that variable even if they hide inside macro definitions).

Did anyone else research and/or write about this issue?

Author: Omer Zak

I am deaf since birth. I played with big computers which eat punched cards and spew out printouts since age 12. Ever since they became available, I work and play with desktop size computers which eat keyboard keypresses and spew out display pixels. Among other things, I developed software which helped the deaf in Israel use the telephone network, by means of home computers equipped with modems. Several years later, I developed Hebrew localizations for some cellular phones, which helped the deaf in Israel utilize the cellular phone networks. I am interested in entrepreneurship, Science Fiction and making the world more accessible to people with disabilities.