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.
Asked
Active
Viewed 661 times
1
-
Could you clarify your question a bit, maybe with an example. I don't quite get what you are asking. – Mike May 15 '09 at 22:20
-
What are x and y? Classes? Objects? Methods? – thecoop May 15 '09 at 22:20
-
Needs clarification, definitely – AAA May 15 '09 at 22:21
3 Answers
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