1

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.

Sverre Rabbelier
  • 1,456
  • 2
  • 16
  • 22

3 Answers3

7

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

user21714
  • 5,781
  • 1
  • 20
  • 26
  • 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 May 15 '09 at 23:57
7

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
  • 4,380
  • 1
  • 20
  • 21
3

Are you thinking of the Law of Demeter?

Gabe Moothart
  • 31,211
  • 14
  • 77
  • 99