<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>simppa.fi/blog &#187; design patterns</title>
	<atom:link href="http://www.simppa.fi/blog/category/design-patterns/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.simppa.fi/blog</link>
	<description>minä kaikkeudessa.</description>
	<lastBuildDate>Wed, 11 Jan 2012 11:10:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>The way we name our classes</title>
		<link>http://www.simppa.fi/blog/way-we-name-our-classes/</link>
		<comments>http://www.simppa.fi/blog/way-we-name-our-classes/#comments</comments>
		<pubDate>Fri, 01 Apr 2011 11:53:27 +0000</pubDate>
		<dc:creator>simo</dc:creator>
				<category><![CDATA[AS3.0]]></category>
		<category><![CDATA[design patterns]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://www.simppa.fi/blog/?p=1061</guid>
		<description><![CDATA[This minor detail has been haunting me for years. It&#8217;s not extremely significant, but really makes a difference with modern coding tools. I&#8217;m talking about the code hinting that all decent coding tools have. It&#8217;s such a priceless feature, but for some reason I often see libs that don&#8217;t take advantage of it. Most libs [...]]]></description>
			<content:encoded><![CDATA[<p>This minor detail has been haunting me for years. It&#8217;s not extremely significant, but really makes a difference with modern coding tools.</p>
<p>I&#8217;m talking about the code hinting that all decent coding tools have. It&#8217;s such a priceless feature, but for some reason I often see libs that don&#8217;t take advantage of it. Most libs are still coded in &#8220;clear English format&#8221;.<br />
<span id="more-1061"></span><br />
For example:</p>
<p><a href="http://www.simppa.fi/blog/wp-content/uploads/2011/04/Screen-shot-2011-04-01-at-2.18.18-PM.png"><img src="http://www.simppa.fi/blog/wp-content/uploads/2011/04/Screen-shot-2011-04-01-at-2.18.18-PM.png" alt="" title="Screen shot 2011-04-01 at 2.18.18 PM" width="413" height="37" class="alignnone size-full wp-image-1066" /></a></p>
<p>Let&#8217;s pretend for a second that you are coding as3 for the first time. You heard that there are filters, but you don&#8217;t know what sort. In this case you need to open your manual and see the filters-section and save the names of all filters into your already overloaded brains. Or at least the first words of them. This leads you to jump back and forward with the manual during your development. For example you would like to add a shadow to image. So you might try to type something like Shad and ask code hint for some guidance. What do you get? Shader this and that&#8230; Where&#8217;s the shadow filter??? After some clicking you find from your manual that the correct word is DropShadowFilter.</p>
<p>Instead all this could be solved with extremely simple naming solution = <strong>FilterShadowDrop</strong>. In this case you could just type Filter and the code hint would serve you a list of all filters at the lib and there could even be different sort of Shadows.</p>
<p>So the idea is to name your classes with type first method. Here&#8217;s an example of lib that contains Frisbee&#8217;s:</p>
<p><a href="http://www.simppa.fi/blog/wp-content/uploads/2011/04/Screen-shot-2011-04-01-at-2.12.59-PM.png"><img src="http://www.simppa.fi/blog/wp-content/uploads/2011/04/Screen-shot-2011-04-01-at-2.12.59-PM.png" alt="" title="Screen shot 2011-04-01 at 2.12.59 PM" width="622" height="148" class="alignnone size-full wp-image-1062" /></a></p>
<p>This is why I&#8217;ve named classes at evoCunningParticleEngine as follows:</p>
<p><a href="http://www.simppa.fi/blog/wp-content/uploads/2011/04/Screen-shot-2011-04-01-at-2.20.46-PM.png"><img src="http://www.simppa.fi/blog/wp-content/uploads/2011/04/Screen-shot-2011-04-01-at-2.20.46-PM.png" alt="" title="Screen shot 2011-04-01 at 2.20.46 PM" width="282" height="340" class="alignnone size-full wp-image-1068" /></a></p>
<p>And this is exactly why command-type classes are named with C-letter at front:</p>
<p><a href="http://www.simppa.fi/blog/wp-content/uploads/2011/04/Screen-shot-2011-04-01-at-2.14.54-PM.png"><img src="http://www.simppa.fi/blog/wp-content/uploads/2011/04/Screen-shot-2011-04-01-at-2.14.54-PM.png" alt="" title="Screen shot 2011-04-01 at 2.14.54 PM" width="398" height="67" class="alignnone size-full wp-image-1063" /></a></p>
<p>I don&#8217;t see why code should be clear English when instead it could be just clear code with good design patterns and named so that it&#8217;s intuitive to use. I can sure you that with this kind of naming the manual paddling will decrease fundamentally. </p>
<p>Or do you disagree?  Am I missing something here?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.simppa.fi/blog/way-we-name-our-classes/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>I wish there would be no more constructor(params:Object)</title>
		<link>http://www.simppa.fi/blog/i-wish-there-would-be-no-more-constructorparamsobject/</link>
		<comments>http://www.simppa.fi/blog/i-wish-there-would-be-no-more-constructorparamsobject/#comments</comments>
		<pubDate>Wed, 12 Nov 2008 15:50:47 +0000</pubDate>
		<dc:creator>simo</dc:creator>
				<category><![CDATA[AS3.0]]></category>
		<category><![CDATA[design patterns]]></category>
		<category><![CDATA[English]]></category>
		<category><![CDATA[flash]]></category>

		<guid isPermaLink="false">http://www.simppa.fi/blog/?p=254</guid>
		<description><![CDATA[I hate this pattern and it&#8217;s very popular these days with as3 API&#8217;s: package &#123; &#160; &#160; &#160; &#160; public class AllMightyClass &#160; &#160; &#160; &#160; &#123; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; public var _value0:String; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; public var _value1:Array; &#160; &#160; &#160; &#160; &#160; &#160; [...]]]></description>
			<content:encoded><![CDATA[<p>I hate this pattern and it&#8217;s very popular these days with as3 API&#8217;s:</p>
<div class="codesnip-container" >
<div class="actionscript codesnip" style="font-family:monospace;">package<br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw2">class</span> AllMightyClass<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw2">var</span> _value0:<span class="kw3">String</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw2">var</span> _value1:<span class="kw3">Array</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw2">var</span> _value2:<span class="kw3">int</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw2">var</span> _value3:<span class="kw3">Object</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw2">function</span> AllMightyClass<span class="br0">&#40;</span>params:<span class="kw3">Object</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _value0 = params.<span class="me1">value0</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _value1 = params.<span class="me1">value1</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _value2 = params.<span class="me1">value2</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _value3 = params.<span class="me1">value3</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span><br />
<span class="co1">// FROM OUTSIDE THIS WOULD LOOK LIKE:</span><br />
<span class="kw2">var</span> amclass:AllMightyClass = <span class="kw2">new</span> AllMightyClass<span class="br0">&#40;</span> <br />
<span class="co1">//editor hints: AllMightyClass(params:Object)</span></div>
</div>
<p>Is this something that people use with some other language or something they learn at school?<br />
It&#8217;s just wrong. The end user has no idea what params it wants or what&#8217;s their type.</p>
<p>Why not use:</p>
<div class="codesnip-container" >
<div class="actionscript codesnip" style="font-family:monospace;">package<br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw2">class</span> Test<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw2">var</span> value0:<span class="kw3">String</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw2">var</span> value1:<span class="kw3">Array</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw2">var</span> value2:<span class="kw3">int</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw2">var</span> value3:<span class="kw3">Object</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw2">function</span> Test<span class="br0">&#40;</span>value0:<span class="kw3">String</span>, value1:<span class="kw3">Array</span>, value2:<span class="kw3">int</span>, value3:<span class="kw3">Object</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">this</span>.<span class="me1">value0</span> = value0;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">this</span>.<span class="me1">value1</span> = value1;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">this</span>.<span class="me1">value2</span> = value2;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">this</span>.<span class="me1">value3</span> = value3;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span><br />
<span class="co1">// FROM OUTSIDE THIS WOULD LOOK LIKE:</span><br />
<span class="kw2">var</span> amclass:AllMightyClass = <span class="kw2">new</span> AllMightyClass<span class="br0">&#40;</span> <br />
<span class="co1">//editor hints: AllMightyClass(value0:String, value1:Array, value2:int, value3:Object)</span></div>
</div>
<p>You may still pass stuff to baseclass in object-format if you like and you may still check if some values are null and then turn them into default. With the first pattern API&#8217;s user need to open the class to see what parameters it swallows or even worse browse the documentation. </p>
<p>But there is even better way to do this:</p>
<div class="codesnip-container" >
<div class="actionscript codesnip" style="font-family:monospace;"><span class="co1">// FIRST CREATE A VALUEOBJECT CLASS</span><br />
package<br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw2">class</span> AllMightyClassVO<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw2">var</span> value0:<span class="kw3">String</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw2">var</span> value1:<span class="kw3">Array</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw2">var</span> value2:<span class="kw3">int</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw2">var</span> value3:<span class="kw3">Object</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw2">function</span> AllMightyClassVO<span class="br0">&#40;</span>value0:<span class="kw3">String</span>, value1:<span class="kw3">Array</span>, value2:<span class="kw3">int</span>, value3:<span class="kw3">Object</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">this</span>.<span class="me1">value0</span> = value0;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">this</span>.<span class="me1">value1</span> = value1;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">this</span>.<span class="me1">value2</span> = value2;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">this</span>.<span class="me1">value3</span> = value3;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></p>
<p><span class="co1">// USE THAT TO PASS YOUR PARAMETERS</span><br />
package <br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw2">class</span> AllMightyClass<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw2">var</span> value0:<span class="kw3">String</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw2">var</span> value1:<span class="kw3">Array</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw2">var</span> value2:<span class="kw3">int</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw2">var</span> value3:<span class="kw3">Object</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw2">function</span> AllMightyClass<span class="br0">&#40;</span>valueObject:AllMightyClassVO<span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">this</span>.<span class="me1">value0</span> = valueObject.<span class="me1">value0</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">this</span>.<span class="me1">value1</span> = valueObject.<span class="me1">value1</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">this</span>.<span class="me1">value2</span> = valueObject.<span class="me1">value2</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">this</span>.<span class="me1">value3</span> = valueObject.<span class="me1">value3</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span><br />
<span class="co1">// FROM OUTSIDE THIS WOULD LOOK LIKE:</span><br />
<span class="kw2">var</span> amclass:AllMightyClass = <span class="kw2">new</span> AllMightyClass<span class="br0">&#40;</span> <br />
<span class="co1">//editor hints: AllMightyClass(valueObject:AllMightyClassVO)</span><br />
<span class="co1">// OK IT EATS AN OBJECT CALLED AllMightyClassVO (let&#8217;s write some more)</span><br />
<span class="kw2">var</span> amclass:AllMightyClass = <span class="kw2">new</span> AllMightyClass<span class="br0">&#40;</span><span class="kw2">new</span> AllMightyClassVO<span class="br0">&#40;</span> <br />
<span class="co1">//editor hints: AllMightyClassVO(value0:String, value1:Array, value2:int, value3:Object)</span></div>
</div>
<p>You can allways extend your VO class with some abstract when you want to pass it down to base classes. This way you make it look intuitive for end user.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.simppa.fi/blog/i-wish-there-would-be-no-more-constructorparamsobject/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

