views:

239

answers:

3

There is a programming "rule" that says that a method should instead of asking for 'x' when it needs to know 'x.y.z', ask directly for 'z'. I just can't remember the name.

+7  A: 

I'm not sure if it's exactly what you're after but this sounds very similar to The Law of Demeter.

Yes, exactly, thanks!
Sverre Rabbelier
Remember that there are always exceptions to the rule. Some projects intentionally break this law to implement Domain Specific Languages (DSLs). Check out JMock, for example.
InverseFalcon
+2  A: 

Are you thinking of the Law of Demeter?

Gabe Moothart
+7  A: 

It's known as the Law of Demeter (a.k.a. Principle of Least Knowledge). See http://en.wikipedia.org/wiki/Law_of_Demeter.

The most vivid and memorable illustration of it I've heard was "When you're paying for a purchase in a store, the clerk doesn't ask you for your wallet so they can extract the money, they ask you for the money!"

Stephen C. Steel