<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/css" href="http://commons.oreilly.com/wiki/skins/common/feed.css?97"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
	<channel>
		<title>Scoping Methods - Revision history</title>
		<link>http://commons.oreilly.com/wiki/index.php?title=Scoping_Methods&amp;action=history</link>
		<description>Revision history for this page on the wiki</description>
		<language>en</language>
		<generator>MediaWiki 1.11.0</generator>
		<lastBuildDate>Sat, 25 May 2013 13:39:00 GMT</lastBuildDate>
		<item>
			<title>Kevlin at 03:14, 19 July 2009</title>
			<link>http://commons.oreilly.com/wiki/index.php?title=Scoping_Methods&amp;diff=24918&amp;oldid=prev</link>
			<description>&lt;p&gt;&lt;/p&gt;

			&lt;table style=&quot;background-color: white; color:black;&quot;&gt;
			&lt;col class='diff-marker' /&gt;
			&lt;col class='diff-content' /&gt;
			&lt;col class='diff-marker' /&gt;
			&lt;col class='diff-content' /&gt;
			&lt;tr&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;←Older revision&lt;/td&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;Revision as of 03:14, 19 July 2009&lt;/td&gt;
			&lt;/tr&gt;
		&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 7:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 7:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;* Local variables are not shared state and are therefore automatically thread safe.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;* Local variables are not shared state and are therefore automatically thread safe.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;But what about scoping &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;of &lt;/del&gt;methods?&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;But what about scoping &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;our &lt;/ins&gt;methods?&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;We try to decompose methods &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;to &lt;/del&gt;smaller units of computation, each of which is easily understandable. &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;That &lt;/del&gt;goes &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;along &lt;/del&gt;with principle &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;that states, &lt;/del&gt;that a method should deal only with a single level of abstraction &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;(SLA)&lt;/del&gt;. If the result &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;is&lt;/del&gt;, that your class then houses too many small methods to be easily understandable, it's time to &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;scope &lt;/del&gt;its methods. &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;That&lt;/del&gt;'s not the same as decomposing classes with low cohesion into different smaller classes.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;We try to decompose methods &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;into &lt;/ins&gt;smaller units of computation, each of which is easily understandable. &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;This &lt;/ins&gt;goes &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;hand in hand &lt;/ins&gt;with &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;the &lt;/ins&gt;principle that a method should deal only with a &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;''&lt;/ins&gt;single level of abstraction&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;''&lt;/ins&gt;. If the result, &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;however, is &lt;/ins&gt;that your class then houses too many small methods to be easily understandable, it's time to &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;rescope &lt;/ins&gt;its methods. &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;Although similar in some ways, that&lt;/ins&gt;'s not &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;quite &lt;/ins&gt;the same as decomposing classes with low cohesion into different smaller classes&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;. The class may be quite cohesive, it's just that is spans too many levels of abstraction&lt;/ins&gt;.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;Although there are layout rules that make locality and access more significant (like putting a private method just below the first method that uses it), scoping is a cleaner way of separating cohesive parts of a class.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;Although there are layout rules that make locality and access more significant (like putting a private method just below the first method that uses it), scoping is a cleaner way of separating cohesive parts of a class.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 15:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 15:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;How to scope methods?&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;How to scope methods?&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;Create objects &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;for &lt;/del&gt;the public methods and move the &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;used &lt;/del&gt;private &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;ones along with them&lt;/del&gt;. If you had parameter lists &amp;amp;mdash; especially long ones &amp;amp;mdash; &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;for the private methods &lt;/del&gt;you can promote these parameters to instance variables of the method object.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;Create objects &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;that correspond to &lt;/ins&gt;the public methods&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;, &lt;/ins&gt;and move the &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;related &lt;/ins&gt;private &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;methods over to the method objects&lt;/ins&gt;. If you had parameter lists &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;for the private methods &lt;/ins&gt;&amp;amp;mdash; especially long ones &amp;amp;mdash; you can promote &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;these some of &lt;/ins&gt;these parameters to instance variables of the method object.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;You then have your original class declare its dependencies on these fragments and orchestrate their invocation. This keeps your original class in a coordinating role, freed from the detail of private methods. The lifetime of your method objects depends on their intended use. Mostly I create them within the scope just before being called and let them die immediately after. You may also choose to give them more significant status and have them passed in from outside the object or created by a factory.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;You then have your original class declare its dependencies on these fragments and orchestrate their invocation. This keeps your original class in a coordinating role, freed from the detail of private methods. The lifetime of your method objects depends on their intended use. Mostly I create them within the scope just before being called and let them die immediately after. You may also choose to give them more significant status and have them passed in from outside the object or created by a factory.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;These method objects give the newly created method scope a name and a location. They stay very narrowly focused and at a consistent level of abstraction. Often they become home for more functionality working on the state &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;the &lt;/del&gt;took with them &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;(&lt;/del&gt;e.g., promoted parameters or instance variables used by just these methods&lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;)&lt;/del&gt;.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;These method objects give the newly created method scope a name and a location. They stay very narrowly focused and at a consistent level of abstraction. Often they become home for more functionality working on the state &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;they &lt;/ins&gt;took with them&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;, &lt;/ins&gt;e.g., &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;the &lt;/ins&gt;promoted parameters or &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;the &lt;/ins&gt;instance variables used by just these methods.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;If you have private methods that are often reused within different other methods it's perhaps time to accept their importance and promote them to public methods in a separate method object.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;If you have private methods that are often reused within different other methods it's perhaps time to accept their importance and promote them to public methods in a separate method object.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;!-- diff cache key wikicontent:diff:version:1.11a:oldid:24861:newid:24918 --&gt;
&lt;/table&gt;</description>
			<pubDate>Sun, 19 Jul 2009 03:14:12 GMT</pubDate>			<dc:creator>Kevlin</dc:creator>			<comments>http://commons.oreilly.com/wiki/index.php/Talk:Scoping_Methods</comments>		</item>
		<item>
			<title>Michael Hunger at 01:17, 17 July 2009</title>
			<link>http://commons.oreilly.com/wiki/index.php?title=Scoping_Methods&amp;diff=24861&amp;oldid=prev</link>
			<description>&lt;p&gt;&lt;/p&gt;

			&lt;table style=&quot;background-color: white; color:black;&quot;&gt;
			&lt;col class='diff-marker' /&gt;
			&lt;col class='diff-content' /&gt;
			&lt;col class='diff-marker' /&gt;
			&lt;col class='diff-content' /&gt;
			&lt;tr&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;←Older revision&lt;/td&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;Revision as of 01:17, 17 July 2009&lt;/td&gt;
			&lt;/tr&gt;
		&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 4:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 4:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;* Variables leaving scope are quickly reclaimed from the stack or collected by the garbage collector.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;* Variables leaving scope are quickly reclaimed from the stack or collected by the garbage collector.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;* Invalid reuse of locally scoped variables is impossible.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;* Invalid reuse of locally scoped variables is impossible.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;* &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;An ''assign-once'' strategy (e.g., &amp;lt;code&amp;gt;final&amp;lt;/code&amp;gt; local variables &lt;/del&gt;in &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;Java) is much easier. &lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;* &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;Singular assignment on declaration encourages a functional style and reduces the mental overhead of keeping track of multiple assignments &lt;/ins&gt;in &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;different contexts&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;* Local variables are not shared state and are therefore automatically thread safe.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;* Local variables are not shared state and are therefore automatically thread safe.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;* etc.&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;But what about methods?&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;But what about &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;scoping of &lt;/ins&gt;methods?&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;It's commonly discussed &lt;/del&gt;that &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;you &lt;/del&gt;should &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;manage the visibility &lt;/del&gt;of your methods &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;by making only that public what should &lt;/del&gt;be &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;exposed by the public interface. Keep overrideable &lt;/del&gt;methods &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;for subclasses abstract or empty&lt;/del&gt;. &lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;We try to decompose methods to smaller units of computation, each of which is easily understandable. That goes along with principle that states, &lt;/ins&gt;that &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;a method &lt;/ins&gt;should &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;deal only with a single level &lt;/ins&gt;of &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;abstraction (SLA). If the result is, that &lt;/ins&gt;your &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;class then houses too many small &lt;/ins&gt;methods &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;to &lt;/ins&gt;be &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;easily understandable, it's time to scope its &lt;/ins&gt;methods&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;. That's not the same as decomposing classes with low cohesion into different smaller classes&lt;/ins&gt;.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;Layout &lt;/del&gt;rules &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;can be used to &lt;/del&gt;make locality and access more significant&lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;: public methods first, followed by private methods; or put &lt;/del&gt;a private method &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;near its first usage, &lt;/del&gt;just below the &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;public &lt;/del&gt;method &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;which &lt;/del&gt;uses it.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;Although there are layout &lt;/ins&gt;rules &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;that &lt;/ins&gt;make locality and access more significant &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;(like putting &lt;/ins&gt;a private method just below the &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;first &lt;/ins&gt;method &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;that &lt;/ins&gt;uses it&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;), scoping is a cleaner way of separating cohesive parts of a class&lt;/ins&gt;.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;Why don't we &lt;/del&gt;scope methods &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;as well&lt;/del&gt;?&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;How to &lt;/ins&gt;scope methods?&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;Create objects for the public methods and move the private ones along with them. If you had parameter lists &amp;amp;mdash; especially long ones &amp;amp;mdash; for the private methods you can promote these parameters to instance variables of the method object.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;Create objects for the public methods and move the &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;used &lt;/ins&gt;private ones along with them. If you had parameter lists &amp;amp;mdash; especially long ones &amp;amp;mdash; for the private methods you can promote these parameters to instance variables of the method object.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;You then have your original class declare its dependencies on these fragments and orchestrate their invocation. This keeps your original class in a coordinating role, freed from the detail of private methods. The lifetime of your method objects depends on their intended use. Mostly I create them within the scope just before being called and let them die immediately after. You may also choose to give them more significant status and have them passed in from outside the object or created by a factory.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;You then have your original class declare its dependencies on these fragments and orchestrate their invocation. This keeps your original class in a coordinating role, freed from the detail of private methods. The lifetime of your method objects depends on their intended use. Mostly I create them within the scope just before being called and let them die immediately after. You may also choose to give them more significant status and have them passed in from outside the object or created by a factory.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 22:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 21:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;These method objects give the newly created method scope a name and a location. They stay very narrowly focused and at a consistent level of abstraction. Often they become home for more functionality working on the state the took with them (e.g., promoted parameters or instance variables used by just these methods).&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;These method objects give the newly created method scope a name and a location. They stay very narrowly focused and at a consistent level of abstraction. Often they become home for more functionality working on the state the took with them (e.g., promoted parameters or instance variables used by just these methods).&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;If you have private methods that are &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;quite &lt;/del&gt;often reused within different other methods it's perhaps time to accept their importance and promote them to public methods in a method object.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;If you have private methods that are often reused within different other methods it's perhaps time to accept their importance and promote them to public methods in a &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;separate &lt;/ins&gt;method object.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;By [[Michael Hunger]]&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;By [[Michael Hunger]]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;!-- diff cache key wikicontent:diff:version:1.11a:oldid:24857:newid:24861 --&gt;
&lt;/table&gt;</description>
			<pubDate>Fri, 17 Jul 2009 01:17:40 GMT</pubDate>			<dc:creator>Michael Hunger</dc:creator>			<comments>http://commons.oreilly.com/wiki/index.php/Talk:Scoping_Methods</comments>		</item>
		<item>
			<title>Michael Hunger: Scoping Method moved to Scoping Methods: Typo</title>
			<link>http://commons.oreilly.com/wiki/index.php?title=Scoping_Methods&amp;diff=24857&amp;oldid=prev</link>
			<description>&lt;p&gt;&lt;a href=&quot;/wiki/index.php/Scoping_Method&quot; title=&quot;Scoping Method&quot;&gt;Scoping Method&lt;/a&gt; moved to &lt;a href=&quot;/wiki/index.php/Scoping_Methods&quot; title=&quot;Scoping Methods&quot;&gt;Scoping Methods&lt;/a&gt;: Typo&lt;/p&gt;

			&lt;table style=&quot;background-color: white; color:black;&quot;&gt;
			&lt;col class='diff-marker' /&gt;
			&lt;col class='diff-content' /&gt;
			&lt;col class='diff-marker' /&gt;
			&lt;col class='diff-content' /&gt;
			&lt;tr&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;←Older revision&lt;/td&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;Revision as of 20:42, 16 July 2009&lt;/td&gt;
			&lt;/tr&gt;
		&lt;/table&gt;</description>
			<pubDate>Thu, 16 Jul 2009 20:42:37 GMT</pubDate>			<dc:creator>Michael Hunger</dc:creator>			<comments>http://commons.oreilly.com/wiki/index.php/Talk:Scoping_Methods</comments>		</item>
		<item>
			<title>Michael Hunger: Method Scopes moved to Scoping Method: Title Change</title>
			<link>http://commons.oreilly.com/wiki/index.php?title=Scoping_Methods&amp;diff=24855&amp;oldid=prev</link>
			<description>&lt;p&gt;&lt;a href=&quot;/wiki/index.php/Method_Scopes&quot; title=&quot;Method Scopes&quot;&gt;Method Scopes&lt;/a&gt; moved to &lt;a href=&quot;/wiki/index.php/Scoping_Method&quot; title=&quot;Scoping Method&quot;&gt;Scoping Method&lt;/a&gt;: Title Change&lt;/p&gt;

			&lt;table style=&quot;background-color: white; color:black;&quot;&gt;
			&lt;col class='diff-marker' /&gt;
			&lt;col class='diff-content' /&gt;
			&lt;col class='diff-marker' /&gt;
			&lt;col class='diff-content' /&gt;
			&lt;tr&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;←Older revision&lt;/td&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;Revision as of 20:42, 16 July 2009&lt;/td&gt;
			&lt;/tr&gt;
		&lt;/table&gt;</description>
			<pubDate>Thu, 16 Jul 2009 20:42:12 GMT</pubDate>			<dc:creator>Michael Hunger</dc:creator>			<comments>http://commons.oreilly.com/wiki/index.php/Talk:Scoping_Methods</comments>		</item>
		<item>
			<title>Kevlin at 21:28, 11 July 2009</title>
			<link>http://commons.oreilly.com/wiki/index.php?title=Scoping_Methods&amp;diff=24816&amp;oldid=prev</link>
			<description>&lt;p&gt;&lt;/p&gt;

			&lt;table style=&quot;background-color: white; color:black;&quot;&gt;
			&lt;col class='diff-marker' /&gt;
			&lt;col class='diff-content' /&gt;
			&lt;col class='diff-marker' /&gt;
			&lt;col class='diff-content' /&gt;
			&lt;tr&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;←Older revision&lt;/td&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;Revision as of 21:28, 11 July 2009&lt;/td&gt;
			&lt;/tr&gt;
		&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;== Method scopes ==&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;It has long been recommended that we should scope our variables as narrowly as possible. Why is that so?&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;It has long been known that we should scope our variables as narrow as possible. And with the advent of modern compilers even more so as they move them into the best location in the binary anyway. Why is that so?&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;* Readability is greatly improved if the scope of a named variable is so small &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;that &lt;/ins&gt;you can see its declaration &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;only a few &lt;/ins&gt;lines above its usage.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&amp;#160;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;* Variables leaving scope are quickly &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;reclaimed from the stack or &lt;/ins&gt;collected by the &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;garbage collector&lt;/ins&gt;.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;* Readability is greatly improved if the scope of a named variable is so small you can see its declaration &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;some &lt;/del&gt;lines above its usage.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;* Variables leaving scope are quickly collected by the &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;Garbage Collector&lt;/del&gt;.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;* Invalid reuse of locally scoped variables is impossible.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;* Invalid reuse of locally scoped variables is impossible.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;* ''&lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;Assign &lt;/del&gt;once &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;strategy&lt;/del&gt;'' (final local variables) is much easier. &lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;* &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;An &lt;/ins&gt;''&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;assign-&lt;/ins&gt;once'' &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;strategy &lt;/ins&gt;(&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;e.g., &amp;lt;code&amp;gt;&lt;/ins&gt;final&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;&amp;lt;/code&amp;gt; &lt;/ins&gt;local variables &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;in Java&lt;/ins&gt;) is much easier. &lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;* Local variables are &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;no &lt;/del&gt;shared state and therefore thread safe&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;* Local variables are &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;not &lt;/ins&gt;shared state and &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;are &lt;/ins&gt;therefore &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;automatically &lt;/ins&gt;thread safe&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;.&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;* etc.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;* etc.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;But what about methods?&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;But what about methods?&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;Its &lt;/del&gt;commonly discussed that you should manage the visibility of your methods by making only that public what should be exposed by the public interface. Keep overrideable methods for subclasses abstract or empty. &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;Sometimes there are some layouting &lt;/del&gt;rules &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;like - &lt;/del&gt;first &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;the public then the &lt;/del&gt;private methods&lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;. Or the one from Uncle Bob - &lt;/del&gt;put &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;the &lt;/del&gt;private method near &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;their &lt;/del&gt;first usage &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;(&lt;/del&gt;just below the public method which uses it&lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;)&lt;/del&gt;.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;It's &lt;/ins&gt;commonly discussed that you should manage the visibility of your methods by making only that public what should be exposed by the public interface. Keep overrideable methods for subclasses abstract or empty. &lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;nbsp;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&amp;#160;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;nbsp;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;Layout &lt;/ins&gt;rules &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;can be used to make locality and access more significant: public methods &lt;/ins&gt;first&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;, followed by &lt;/ins&gt;private methods&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;; or &lt;/ins&gt;put &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;a &lt;/ins&gt;private method near &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;its &lt;/ins&gt;first usage&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;, &lt;/ins&gt;just below the public method which uses it.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;Why don't we scope methods as well?&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;Why don't we scope methods as well?&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;It is easy &lt;/del&gt;and &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;helps a lot &lt;/del&gt;with the &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;Single Responsibility Principle (SRP) - have one reason &lt;/del&gt;to &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;change a class - and One Level Of Abstraction - within a (method) scope only have invocations on the same level &lt;/del&gt;of &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;abstraction, no nested structures&lt;/del&gt;. &lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;Create objects for the public methods &lt;/ins&gt;and &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;move the private ones along &lt;/ins&gt;with &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;them. If you had parameter lists &amp;amp;mdash; especially long ones &amp;amp;mdash; for &lt;/ins&gt;the &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;private methods you can promote these parameters &lt;/ins&gt;to &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;instance variables &lt;/ins&gt;of &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;the method object&lt;/ins&gt;.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;Just create objects for the public methods &lt;/del&gt;and &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;move the private ones along with them&lt;/del&gt;. &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;If you had (long) parameter lists for &lt;/del&gt;the private methods &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;you can promote these parameters to instance variables &lt;/del&gt;of &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;the &lt;/del&gt;method object.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;You then have your original class declare its dependencies on these fragments &lt;/ins&gt;and &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;orchestrate their invocation&lt;/ins&gt;. &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;This keeps your original class in a coordinating role, freed from &lt;/ins&gt;the &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;detail of &lt;/ins&gt;private methods&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;. The lifetime &lt;/ins&gt;of &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;your &lt;/ins&gt;method &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;objects depends on their intended use. Mostly I create them within the scope just before being called and let them die immediately after. You may also choose to give them more significant status and have them passed in from outside the &lt;/ins&gt;object &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;or created by a factory&lt;/ins&gt;.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;Then have your original class declare its dependencies on these fragments &lt;/del&gt;and &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;orchestrate their invocation&lt;/del&gt;. &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;This keeps your orchestrating class in a controlling role &lt;/del&gt;and &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;free &lt;/del&gt;of &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;lots of small (as we like it) private methods&lt;/del&gt;. &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;The lifetime of your method objects depends &lt;/del&gt;on &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;their intended use. Mostly I create them within &lt;/del&gt;the &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;scope just before being called and let &lt;/del&gt;them &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;instantly die&lt;/del&gt;. &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;You may also choose to give them higher status and have them injected by an DI framework &lt;/del&gt;or &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;created &lt;/del&gt;by &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;a factory&lt;/del&gt;.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;These method objects give the newly created method scope a name &lt;/ins&gt;and &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;a location&lt;/ins&gt;. &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;They stay very narrowly focused &lt;/ins&gt;and &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;at a consistent level &lt;/ins&gt;of &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;abstraction&lt;/ins&gt;. &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;Often they become home for more functionality working &lt;/ins&gt;on the &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;state the took with &lt;/ins&gt;them &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;(e&lt;/ins&gt;.&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;g., promoted parameters &lt;/ins&gt;or &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;instance variables used &lt;/ins&gt;by &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;just these methods)&lt;/ins&gt;.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;These Method Objects give the newly created method scope a name &lt;/del&gt;and &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;a location. They stay very narrowly focused (SRP). Often they become home for more functionality working on the state the took with &lt;/del&gt;them &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;(e.g. promoted parameters or instance variables used by just these &lt;/del&gt;methods.&lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;)&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;If you have private methods that are quite often reused within different other methods it's perhaps time to accept their importance &lt;/ins&gt;and &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;promote &lt;/ins&gt;them &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;to public &lt;/ins&gt;methods &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;in a method object&lt;/ins&gt;.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;If you have private methods that are quite often reused within different other methods it's perhaps time to accept their importance and promote them to public methods in a Method Object (or utility class -&amp;gt; traditional function for non-functional languages)&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;By [[Michael Hunger]]&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;Partially this is comparable with AOP but this approach makes the delegated functionality visible as these are no cross cutting (technical) concerns but business functionality. A much better discussion about this principle is done by Jim Coplien (DCI - data context interaction) and Rickard Öbergs (COP - composite oriented programming, available in the qi4j framework) which focus on composing objects out of many fragments depending on the current role of the object within the current execution context.&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;Further Reading&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;This work is licensed under a&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;# Rickard Öbergs qi4j &lt;/del&gt;[http://&lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;qi4j&lt;/del&gt;.org&lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;]&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;[http://&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;creativecommons&lt;/ins&gt;.org/&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;licenses&lt;/ins&gt;/&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;by/3&lt;/ins&gt;.&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;0&lt;/ins&gt;/&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;us&lt;/ins&gt;/ &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;Creative Commons Attribution 3&lt;/ins&gt;]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;# Jim Copliens DCI [http:&lt;/del&gt;//&lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;blog&lt;/del&gt;.&lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;jaoo.dk&lt;/del&gt;/&lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;2008/09/30/object-oriented-architecture-as-it-should-have-been-agile-architecture&lt;/del&gt;/]&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;# Method Object Pattern (Design Patterns, GoF)&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;# Refactoring (Martin Fowler)&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;# Clean Code (Bob Martin)&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;--&lt;/del&gt;[[&lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;User:Michael Hunger|Michael Hunger&lt;/del&gt;]] &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;13:14, 29 January 2009 (PST)&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;Back to &lt;/ins&gt;[[&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;97 Things Every Programmer Should Know&lt;/ins&gt;]] &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;home page&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;!-- diff cache key wikicontent:diff:version:1.11a:oldid:23183:newid:24816 --&gt;
&lt;/table&gt;</description>
			<pubDate>Sat, 11 Jul 2009 21:28:43 GMT</pubDate>			<dc:creator>Kevlin</dc:creator>			<comments>http://commons.oreilly.com/wiki/index.php/Talk:Scoping_Methods</comments>		</item>
		<item>
			<title>Michael Hunger: /* Method scopes */</title>
			<link>http://commons.oreilly.com/wiki/index.php?title=Scoping_Methods&amp;diff=23183&amp;oldid=prev</link>
			<description>&lt;p&gt;&lt;span class=&quot;autocomment&quot;&gt;Method scopes&lt;/span&gt;&lt;/p&gt;

			&lt;table style=&quot;background-color: white; color:black;&quot;&gt;
			&lt;col class='diff-marker' /&gt;
			&lt;col class='diff-content' /&gt;
			&lt;col class='diff-marker' /&gt;
			&lt;col class='diff-content' /&gt;
			&lt;tr&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;←Older revision&lt;/td&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;Revision as of 21:14, 29 January 2009&lt;/td&gt;
			&lt;/tr&gt;
		&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 27:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 27:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;Partially this is comparable with AOP but this approach makes the delegated functionality visible as these are no cross cutting (technical) concerns but business functionality. A much better discussion about this principle is done by Jim Coplien (DCI - data context interaction) and Rickard Öbergs (COP - composite oriented programming, available in the qi4j framework) which focus on composing objects out of many fragments depending on the current role of the object within the current execution context.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;Partially this is comparable with AOP but this approach makes the delegated functionality visible as these are no cross cutting (technical) concerns but business functionality. A much better discussion about this principle is done by Jim Coplien (DCI - data context interaction) and Rickard Öbergs (COP - composite oriented programming, available in the qi4j framework) which focus on composing objects out of many fragments depending on the current role of the object within the current execution context.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;nbsp;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;nbsp;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;Further Reading&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;nbsp;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;# Rickard Öbergs qi4j [http://qi4j.org]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;nbsp;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;# Jim Copliens DCI [http://blog.jaoo.dk/2008/09/30/object-oriented-architecture-as-it-should-have-been-agile-architecture/]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;nbsp;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;# Method Object Pattern (Design Patterns, GoF)&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;nbsp;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;# Refactoring (Martin Fowler)&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;nbsp;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;# Clean Code (Bob Martin)&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;nbsp;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;nbsp;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;--[[User:Michael Hunger|Michael Hunger]] 13:14, 29 January 2009 (PST)&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;!-- diff cache key wikicontent:diff:version:1.11a:oldid:23126:newid:23183 --&gt;
&lt;/table&gt;</description>
			<pubDate>Thu, 29 Jan 2009 21:14:13 GMT</pubDate>			<dc:creator>Michael Hunger</dc:creator>			<comments>http://commons.oreilly.com/wiki/index.php/Talk:Scoping_Methods</comments>		</item>
		<item>
			<title>Michael Hunger: New page: == Method scopes ==  It has long been known that we should scope our variables as narrow as possible. And with the advent of modern compilers even more so as they move them into the best l...</title>
			<link>http://commons.oreilly.com/wiki/index.php?title=Scoping_Methods&amp;diff=23126&amp;oldid=prev</link>
			<description>&lt;p&gt;New page: == Method scopes ==  It has long been known that we should scope our variables as narrow as possible. And with the advent of modern compilers even more so as they move them into the best l...&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;== Method scopes ==&lt;br /&gt;
&lt;br /&gt;
It has long been known that we should scope our variables as narrow as possible. And with the advent of modern compilers even more so as they move them into the best location in the binary anyway. Why is that so?&lt;br /&gt;
&lt;br /&gt;
* Readability is greatly improved if the scope of a named variable is so small you can see its declaration some lines above its usage.&lt;br /&gt;
* Variables leaving scope are quickly collected by the Garbage Collector.&lt;br /&gt;
* Invalid reuse of locally scoped variables is impossible.&lt;br /&gt;
* ''Assign once strategy'' (final local variables) is much easier. &lt;br /&gt;
* Local variables are no shared state and therefore thread safe&lt;br /&gt;
* etc.&lt;br /&gt;
&lt;br /&gt;
But what about methods?&lt;br /&gt;
&lt;br /&gt;
Its commonly discussed that you should manage the visibility of your methods by making only that public what should be exposed by the public interface. Keep overrideable methods for subclasses abstract or empty. Sometimes there are some layouting rules like - first the public then the private methods. Or the one from Uncle Bob - put the private method near their first usage (just below the public method which uses it).&lt;br /&gt;
&lt;br /&gt;
Why don't we scope methods as well?&lt;br /&gt;
&lt;br /&gt;
It is easy and helps a lot with the Single Responsibility Principle (SRP) - have one reason to change a class - and One Level Of Abstraction - within a (method) scope only have invocations on the same level of abstraction, no nested structures. &lt;br /&gt;
&lt;br /&gt;
Just create objects for the public methods and move the private ones along with them. If you had (long) parameter lists for the private methods you can promote these parameters to instance variables of the method object.&lt;br /&gt;
&lt;br /&gt;
Then have your original class declare its dependencies on these fragments and orchestrate their invocation. This keeps your orchestrating class in a controlling role and free of lots of small (as we like it) private methods. The lifetime of your method objects depends on their intended use. Mostly I create them within the scope just before being called and let them instantly die. You may also choose to give them higher status and have them injected by an DI framework or created by a factory.&lt;br /&gt;
&lt;br /&gt;
These Method Objects give the newly created method scope a name and a location. They stay very narrowly focused (SRP). Often they become home for more functionality working on the state the took with them (e.g. promoted parameters or instance variables used by just these methods.)&lt;br /&gt;
&lt;br /&gt;
If you have private methods that are quite often reused within different other methods it's perhaps time to accept their importance and promote them to public methods in a Method Object (or utility class -&amp;gt; traditional function for non-functional languages)&lt;br /&gt;
&lt;br /&gt;
Partially this is comparable with AOP but this approach makes the delegated functionality visible as these are no cross cutting (technical) concerns but business functionality. A much better discussion about this principle is done by Jim Coplien (DCI - data context interaction) and Rickard Öbergs (COP - composite oriented programming, available in the qi4j framework) which focus on composing objects out of many fragments depending on the current role of the object within the current execution context.&lt;/div&gt;</description>
			<pubDate>Tue, 27 Jan 2009 03:20:50 GMT</pubDate>			<dc:creator>Michael Hunger</dc:creator>			<comments>http://commons.oreilly.com/wiki/index.php/Talk:Scoping_Methods</comments>		</item>
	</channel>
</rss>