<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://mediawiki.zeropage.org/index.php?action=history&amp;feed=atom&amp;title=LawOfDemeter</id>
	<title>LawOfDemeter - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://mediawiki.zeropage.org/index.php?action=history&amp;feed=atom&amp;title=LawOfDemeter"/>
	<link rel="alternate" type="text/html" href="https://mediawiki.zeropage.org/index.php?title=LawOfDemeter&amp;action=history"/>
	<updated>2026-05-15T18:17:16Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.39.8</generator>
	<entry>
		<id>https://mediawiki.zeropage.org/index.php?title=LawOfDemeter&amp;diff=34144&amp;oldid=prev</id>
		<title>imported&gt;Unknown at 05:23, 7 February 2021</title>
		<link rel="alternate" type="text/html" href="https://mediawiki.zeropage.org/index.php?title=LawOfDemeter&amp;diff=34144&amp;oldid=prev"/>
		<updated>2021-02-07T05:23:37Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;* http://www.ccs.neu.edu/home/lieber/LoD.html&lt;br /&gt;
&lt;br /&gt;
다음은 http://www.pragmaticprogrammer.com/ppllc/papers/1998_05.html 중 &amp;#039;Law Of Demeter&amp;#039; 에 대한 글.&lt;br /&gt;
&lt;br /&gt;
 So we&amp;#039;ve decided to expose as little state as we need to in order to accomplish our goals. Great! Now &lt;br /&gt;
 within our class can we just starting sending commands and queries to any other object in the system will-&lt;br /&gt;
 nilly? Well, you could, but that would be a bad idea, according to the Law of Demeter. The Law of Demeter &lt;br /&gt;
 tries to restrict class interaction in order to minimize coupling among classes. (For a good discussion on &lt;br /&gt;
 this topic, see [APPLETON]). &lt;br /&gt;
&lt;br /&gt;
 What that means is that the more objects you talk to, the more you run the risk of getting broken when one &lt;br /&gt;
 of them changes. So not only do you want to say as little as possible, you don&amp;#039;t want to talk to more &lt;br /&gt;
 objects than you need to either. In fact, according to the Law of Demeter for Methods, any method of an &lt;br /&gt;
 object should only call methods belonging to: &lt;br /&gt;
&lt;br /&gt;
 itself. &lt;br /&gt;
 any parameters that were passed in to the method. &lt;br /&gt;
 any objects it created. &lt;br /&gt;
 any composite objects. &lt;br /&gt;
 Specifically missing from this list is methods belonging to objects that were returned from some other &lt;br /&gt;
 call. For example (we&amp;#039;ll use Java syntax here): &lt;br /&gt;
&lt;br /&gt;
        SortedList thingy = someObject.getEmployeeList();&lt;br /&gt;
        thingy.addElementWithKey(foo.getKey(), foo);&lt;br /&gt;
&lt;br /&gt;
 This is what we are trying to prevent. (We also have an example of Asking instead of Telling in foo.getKey&lt;br /&gt;
 ()). Direct access of a child like this extends coupling from the caller farther than it needs to be. The &lt;br /&gt;
 caller is depending on these facts: &lt;br /&gt;
&lt;br /&gt;
 someObject holds employees in a SortedList. &lt;br /&gt;
 SortedList&amp;#039;s add method is addElementWithKey() &lt;br /&gt;
 foo&amp;#039;s method to query its key is getKey() &lt;br /&gt;
 Instead, this should be: &lt;br /&gt;
&lt;br /&gt;
        someObject.addToThingy(foo);&lt;br /&gt;
&lt;br /&gt;
 Now the caller is only depending on the fact that it can add a foo to thingy, which sounds high level &lt;br /&gt;
 enough to have been a responsibility, not too dependent on implementation. &lt;br /&gt;
&lt;br /&gt;
 The disadvantage, of course, is that you end up writing many small wrapper methods that do very little but &lt;br /&gt;
 delegate container traversal and such. The cost tradeoff is between that inefficiency and higher class &lt;br /&gt;
 coupling. &lt;br /&gt;
&lt;br /&gt;
 The higher the degree of coupling between classes, the higher the odds that any change you make will break &lt;br /&gt;
 something somewhere else. This tends to create fragile, brittle code. &lt;br /&gt;
&lt;br /&gt;
 Depending on your application, the development and maintenance costs of high class coupling may easily &lt;br /&gt;
 swamp run-time inefficiencies in most cases. &lt;br /&gt;
&lt;br /&gt;
 Command/Query Separation&lt;br /&gt;
 Now back to to the ask vs. tell thing. To ask is a query, to tell is a command. I subscribe to the notion &lt;br /&gt;
 of maintaining these as separate methods. Why bother? &lt;br /&gt;
&lt;br /&gt;
 It helps to maintain the &amp;quot;Tell, Don&amp;#039;t Ask&amp;quot; principle if you think in terms of commands that perform a very &lt;br /&gt;
 specific, well defined action. &lt;br /&gt;
&lt;br /&gt;
 It helps you to think about class invariants if you class is primarily command based. (If you are just &lt;br /&gt;
 tossing data out, you probably aren&amp;#039;t thinking much in the way of invariants). &lt;br /&gt;
&lt;br /&gt;
 If you can assume that evaluation of a query is free of any side effects, then you can: &lt;br /&gt;
&lt;br /&gt;
 use queries from within a debugger without affecting the process under test. &lt;br /&gt;
 create built-in, automatic regression tests. &lt;br /&gt;
 evaluate class invariants, pre- and post-conditions. &lt;br /&gt;
&lt;br /&gt;
 The last, of course, is why Eiffel requires only side-effect free methods to be called from within an &lt;br /&gt;
 Assertion. But even in C++ or Java, if you want to manually check the state of an object at some point in &lt;br /&gt;
 the code, you can do so with confidence if you know the queries you are calling will not cause anything &lt;br /&gt;
 else to change.&lt;br /&gt;
&lt;/div&gt;</summary>
		<author><name>imported&gt;Unknown</name></author>
	</entry>
</feed>