<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>
<channel>
	<title>Comments on: Let&#8217;s Get Rid of Conditionals!</title>
	<atom:link href="http://www.as3dp.com/2007/12/21/lets-get-rid-of-conditionals/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.as3dp.com/2007/12/21/lets-get-rid-of-conditionals/</link>
	<description>OOP for Flash, Flex and AIR</description>
	<pubDate>Thu, 24 Jul 2008 07:04:37 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6</generator>
		<item>
		<title>By: Bill Sanders</title>
		<link>http://www.as3dp.com/2007/12/21/lets-get-rid-of-conditionals/#comment-577</link>
		<dc:creator>Bill Sanders</dc:creator>
		<pubDate>Fri, 25 Apr 2008 20:34:31 +0000</pubDate>
		<guid isPermaLink="false">http://www.as3dp.com/2007/12/21/lets-get-rid-of-conditionals/#comment-577</guid>
		<description>Mike,

Hey, pseudo-code is fine. It gets the idea across, and I really am planning on getting back to the dual dispatch concept written in AS 3.0 as soon as I can get the Mediator wrestled to the ground. I'm trying to work through how one abstract class can hold a reference to another abstract class/interface. If I can quickly get Dan's code running in AS 3.0, I'll do it. (Unless someone else would like a shot....)

Take care,
Bill</description>
		<content:encoded><![CDATA[<p>Mike,</p>
<p>Hey, pseudo-code is fine. It gets the idea across, and I really am planning on getting back to the dual dispatch concept written in AS 3.0 as soon as I can get the Mediator wrestled to the ground. I&#8217;m trying to work through how one abstract class can hold a reference to another abstract class/interface. If I can quickly get Dan&#8217;s code running in AS 3.0, I&#8217;ll do it. (Unless someone else would like a shot&#8230;.)</p>
<p>Take care,<br />
Bill</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mike Anderson</title>
		<link>http://www.as3dp.com/2007/12/21/lets-get-rid-of-conditionals/#comment-575</link>
		<dc:creator>Mike Anderson</dc:creator>
		<pubDate>Fri, 25 Apr 2008 17:43:42 +0000</pubDate>
		<guid isPermaLink="false">http://www.as3dp.com/2007/12/21/lets-get-rid-of-conditionals/#comment-575</guid>
		<description>I'm not going OOPSLA, I've been out of the programming business for a while now (although I'm getting back into it with Flash).

The code I posted is just pseudo-code (hopefully looks like AS) which was just a translation of Dan Ingall's Smalltalk code snippets.

Let me just make another point about OOP and conditionals.  An OOP program or system is a fundamentally little more than a bunch of conditionals.  An object in a true OOP language, I'd argue, has 3 things: identity, instance data, and behavior.  The behavior of an object is analogous to a big switch statement mapping method selectors (messsage names or method signatures) to actions.  Given this, often a switch statement can be refactored into a message send and vice versa.  (There are many factors that influence when this refactoring is a good idea and I'll leave that to further discussion.)

...Mike</description>
		<content:encoded><![CDATA[<p>I&#8217;m not going OOPSLA, I&#8217;ve been out of the programming business for a while now (although I&#8217;m getting back into it with Flash).</p>
<p>The code I posted is just pseudo-code (hopefully looks like AS) which was just a translation of Dan Ingall&#8217;s Smalltalk code snippets.</p>
<p>Let me just make another point about OOP and conditionals.  An OOP program or system is a fundamentally little more than a bunch of conditionals.  An object in a true OOP language, I&#8217;d argue, has 3 things: identity, instance data, and behavior.  The behavior of an object is analogous to a big switch statement mapping method selectors (messsage names or method signatures) to actions.  Given this, often a switch statement can be refactored into a message send and vice versa.  (There are many factors that influence when this refactoring is a good idea and I&#8217;ll leave that to further discussion.)</p>
<p>&#8230;Mike</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bill Sanders</title>
		<link>http://www.as3dp.com/2007/12/21/lets-get-rid-of-conditionals/#comment-574</link>
		<dc:creator>Bill Sanders</dc:creator>
		<pubDate>Thu, 24 Apr 2008 22:06:46 +0000</pubDate>
		<guid isPermaLink="false">http://www.as3dp.com/2007/12/21/lets-get-rid-of-conditionals/#comment-574</guid>
		<description>Hi Mike,

Are you going to OOPSLA in Nashville later this year? I hope to be able to have a presentation there in the same session I have for the last two years (Killer Apps). It would be great to see someone else using ActionScript there.

 Did you do it with Flex or Flash?

Thanks,
Bill</description>
		<content:encoded><![CDATA[<p>Hi Mike,</p>
<p>Are you going to OOPSLA in Nashville later this year? I hope to be able to have a presentation there in the same session I have for the last two years (Killer Apps). It would be great to see someone else using ActionScript there.</p>
<p> Did you do it with Flex or Flash?</p>
<p>Thanks,<br />
Bill</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mike Anderson</title>
		<link>http://www.as3dp.com/2007/12/21/lets-get-rid-of-conditionals/#comment-573</link>
		<dc:creator>Mike Anderson</dc:creator>
		<pubDate>Thu, 24 Apr 2008 17:07:07 +0000</pubDate>
		<guid isPermaLink="false">http://www.as3dp.com/2007/12/21/lets-get-rid-of-conditionals/#comment-573</guid>
		<description>Here's the basic example ported from Dan Ingalls "A Simple Technique for Handling Multiple Polymorphism" paper at OOPSLA 86 (this is the first explanation of DD that I know of - the term "double dispatching" wasn't in use back then - it's a nice terse 3 page explanation that seems to be locked up in the &lt;a href="http://portal.acm.org/citation.cfm?id=960112.28732&#38;coll=portal&#38;dl=ACM&#38;CFID=63150411&#38;CFTOKEN=31475536" rel="nofollow"&gt;
vaults of the ACM&lt;/a&gt;):
&lt;pre lang="actionscript"&gt;
public interface IDisplayPort {
    function displayRect (r:Rectangle): void;
    function displayString (t:Text): void;
    function displayOval (r:Rectangle): void;
    function displayBitmap (b:Bitmap): void;
}
public interface IDisplayObject {
    function displayOn (port:IDisplayPort): void;
}
public class Rectangle implements IDisplayObject {   
     function displayOn (port:IDisplayPort) {
        port.displayRectangle (this);
    }
}
public class Bitmap implements IDisplayObject {
    function displayOn (port:IDisplayPort) {
        port.displayBitmap (this);
    }
}
public class Oval implements IDisplayObject {
    function displayOn (port:IDisplayPort) {
        port.displayOval (this.boundingBox ());
    }
public class Text implements IDisplayObject {
    function displayOn (port:IDisplayPort) {
        port.displayText (this):
    }
}
&lt;/pre&gt;

Likely implementors of IDisplayPort are screen objects, printers, bitmaps, graphic files, etc.
Now if you're positive you need exactly 2 kinds of display ports and exactly 2 kinds of display objects, putting all the login in a single method with conditionals is easier.  But if there are many kinds of display ports and many kinds of display objects, double dispatching makes it much more manageable. It resolves (without conditionals) one kind of display object paired with one kind of display port to a single method (er, function).  This same technique can be extended to triple dispatching (and more).

...Mike</description>
		<content:encoded><![CDATA[<p>Here&#8217;s the basic example ported from Dan Ingalls &#8220;A Simple Technique for Handling Multiple Polymorphism&#8221; paper at OOPSLA 86 (this is the first explanation of DD that I know of - the term &#8220;double dispatching&#8221; wasn&#8217;t in use back then - it&#8217;s a nice terse 3 page explanation that seems to be locked up in the <a href="http://portal.acm.org/citation.cfm?id=960112.28732&amp;coll=portal&amp;dl=ACM&amp;CFID=63150411&amp;CFTOKEN=31475536" rel="nofollow"><br />
vaults of the ACM</a>):</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript"><span style="color: #0066CC;">public</span> <span style="color: #0066CC;">interface</span> IDisplayPort <span style="color: #66cc66;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">function</span> displayRect <span style="color: #66cc66;">&#40;</span>r:Rectangle<span style="color: #66cc66;">&#41;</span>: <span style="color: #0066CC;">void</span>;
    <span style="color: #000000; font-weight: bold;">function</span> displayString <span style="color: #66cc66;">&#40;</span>t:<span style="color: #0066CC;">Text</span><span style="color: #66cc66;">&#41;</span>: <span style="color: #0066CC;">void</span>;
    <span style="color: #000000; font-weight: bold;">function</span> displayOval <span style="color: #66cc66;">&#40;</span>r:Rectangle<span style="color: #66cc66;">&#41;</span>: <span style="color: #0066CC;">void</span>;
    <span style="color: #000000; font-weight: bold;">function</span> displayBitmap <span style="color: #66cc66;">&#40;</span>b:Bitmap<span style="color: #66cc66;">&#41;</span>: <span style="color: #0066CC;">void</span>;
<span style="color: #66cc66;">&#125;</span>
<span style="color: #0066CC;">public</span> <span style="color: #0066CC;">interface</span> IDisplayObject <span style="color: #66cc66;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">function</span> displayOn <span style="color: #66cc66;">&#40;</span>port:IDisplayPort<span style="color: #66cc66;">&#41;</span>: <span style="color: #0066CC;">void</span>;
<span style="color: #66cc66;">&#125;</span>
<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Rectangle <span style="color: #0066CC;">implements</span> IDisplayObject <span style="color: #66cc66;">&#123;</span>   
     <span style="color: #000000; font-weight: bold;">function</span> displayOn <span style="color: #66cc66;">&#40;</span>port:IDisplayPort<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
        port.<span style="color: #006600;">displayRectangle</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">this</span><span style="color: #66cc66;">&#41;</span>;
    <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span>
<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Bitmap <span style="color: #0066CC;">implements</span> IDisplayObject <span style="color: #66cc66;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">function</span> displayOn <span style="color: #66cc66;">&#40;</span>port:IDisplayPort<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
        port.<span style="color: #006600;">displayBitmap</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">this</span><span style="color: #66cc66;">&#41;</span>;
    <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span>
<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Oval <span style="color: #0066CC;">implements</span> IDisplayObject <span style="color: #66cc66;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">function</span> displayOn <span style="color: #66cc66;">&#40;</span>port:IDisplayPort<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
        port.<span style="color: #006600;">displayOval</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">this</span>.<span style="color: #006600;">boundingBox</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
    <span style="color: #66cc66;">&#125;</span>
<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> <span style="color: #0066CC;">Text</span> <span style="color: #0066CC;">implements</span> IDisplayObject <span style="color: #66cc66;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">function</span> displayOn <span style="color: #66cc66;">&#40;</span>port:IDisplayPort<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
        port.<span style="color: #006600;">displayText</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">this</span><span style="color: #66cc66;">&#41;</span>:
    <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>Likely implementors of IDisplayPort are screen objects, printers, bitmaps, graphic files, etc.<br />
Now if you&#8217;re positive you need exactly 2 kinds of display ports and exactly 2 kinds of display objects, putting all the login in a single method with conditionals is easier.  But if there are many kinds of display ports and many kinds of display objects, double dispatching makes it much more manageable. It resolves (without conditionals) one kind of display object paired with one kind of display port to a single method (er, function).  This same technique can be extended to triple dispatching (and more).</p>
<p>&#8230;Mike</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bill Sanders</title>
		<link>http://www.as3dp.com/2007/12/21/lets-get-rid-of-conditionals/#comment-572</link>
		<dc:creator>Bill Sanders</dc:creator>
		<pubDate>Thu, 24 Apr 2008 12:23:55 +0000</pubDate>
		<guid isPermaLink="false">http://www.as3dp.com/2007/12/21/lets-get-rid-of-conditionals/#comment-572</guid>
		<description>Hi Mike,

Welcome to the discussion. Now I've got to admit that I don't know jack about double dispatching, but I'm willing to learn. How about a piece of sample code in ActionScript 3.0 or a little app that uses it? Maybe even a little DP that shows what DD can do.

I found a clear description of double-dispatch on page 338 of the GoF's book, &lt;em&gt;Design Patterns&lt;/em&gt;, and right after the Mediator DP that I'm working on now, I'll have a run at the Visitor pattern that uses double-dispatch. The Visitor patterns allows you to add operations (methods?) to classes without changing them. The executed operation depends on the kind of request and the types of &lt;em&gt;two receivers&lt;/em&gt;. It sounds intriguing and as you said, negates the requirement for a conditional.

Naturally, if you'd like to show us how ActionScript 3.0 can be employed in a simple Visitor pattern; we'd be delighted!

Thanks a million,
Bill</description>
		<content:encoded><![CDATA[<p>Hi Mike,</p>
<p>Welcome to the discussion. Now I&#8217;ve got to admit that I don&#8217;t know jack about double dispatching, but I&#8217;m willing to learn. How about a piece of sample code in ActionScript 3.0 or a little app that uses it? Maybe even a little DP that shows what DD can do.</p>
<p>I found a clear description of double-dispatch on page 338 of the GoF&#8217;s book, <em>Design Patterns</em>, and right after the Mediator DP that I&#8217;m working on now, I&#8217;ll have a run at the Visitor pattern that uses double-dispatch. The Visitor patterns allows you to add operations (methods?) to classes without changing them. The executed operation depends on the kind of request and the types of <em>two receivers</em>. It sounds intriguing and as you said, negates the requirement for a conditional.</p>
<p>Naturally, if you&#8217;d like to show us how ActionScript 3.0 can be employed in a simple Visitor pattern; we&#8217;d be delighted!</p>
<p>Thanks a million,<br />
Bill</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mike Anderson</title>
		<link>http://www.as3dp.com/2007/12/21/lets-get-rid-of-conditionals/#comment-571</link>
		<dc:creator>Mike Anderson</dc:creator>
		<pubDate>Thu, 24 Apr 2008 08:22:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.as3dp.com/2007/12/21/lets-get-rid-of-conditionals/#comment-571</guid>
		<description>Hi guys, interesting site, stuff.  I'm new to ActionScript, but I once was a Smalltalk programmer, so of course I'll claim you can do much programming (comfortably) without conditionals.

Smalltalk didn't have conditionals (syntactically) - the effect was achieved with the behavior of Booleans and Blocks.  I don't think this is feasible in ActionScript because you can't add the requisite behavior to all the booleans you're likely to encounter (I don't think).  But ActionScript is so much more dynamically flexible than languages from which it inherited it's syntax (C, Java), it supports a style of programming much less reliant on conditional syntax.

Which brings me to my favorite pattern, the most overlooked and fundamental pattern of all time: double dispatching.  Double dispatching can be used to significantly reduce conditionals, often  leads to "better" factored code (IMHO).

...Mike</description>
		<content:encoded><![CDATA[<p>Hi guys, interesting site, stuff.  I&#8217;m new to ActionScript, but I once was a Smalltalk programmer, so of course I&#8217;ll claim you can do much programming (comfortably) without conditionals.</p>
<p>Smalltalk didn&#8217;t have conditionals (syntactically) - the effect was achieved with the behavior of Booleans and Blocks.  I don&#8217;t think this is feasible in ActionScript because you can&#8217;t add the requisite behavior to all the booleans you&#8217;re likely to encounter (I don&#8217;t think).  But ActionScript is so much more dynamically flexible than languages from which it inherited it&#8217;s syntax (C, Java), it supports a style of programming much less reliant on conditional syntax.</p>
<p>Which brings me to my favorite pattern, the most overlooked and fundamental pattern of all time: double dispatching.  Double dispatching can be used to significantly reduce conditionals, often  leads to &#8220;better&#8221; factored code (IMHO).</p>
<p>&#8230;Mike</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bill Sanders</title>
		<link>http://www.as3dp.com/2007/12/21/lets-get-rid-of-conditionals/#comment-564</link>
		<dc:creator>Bill Sanders</dc:creator>
		<pubDate>Tue, 22 Apr 2008 11:54:20 +0000</pubDate>
		<guid isPermaLink="false">http://www.as3dp.com/2007/12/21/lets-get-rid-of-conditionals/#comment-564</guid>
		<description>Hi Erik,

Each case is a different class. As each class is called, all of the possible and/or correct conditions are put forth. It's a lot more work, but it takes out the conditional switch statement.

Bill</description>
		<content:encoded><![CDATA[<p>Hi Erik,</p>
<p>Each case is a different class. As each class is called, all of the possible and/or correct conditions are put forth. It&#8217;s a lot more work, but it takes out the conditional switch statement.</p>
<p>Bill</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Erik</title>
		<link>http://www.as3dp.com/2007/12/21/lets-get-rid-of-conditionals/#comment-553</link>
		<dc:creator>Erik</dc:creator>
		<pubDate>Tue, 15 Apr 2008 08:40:24 +0000</pubDate>
		<guid isPermaLink="false">http://www.as3dp.com/2007/12/21/lets-get-rid-of-conditionals/#comment-553</guid>
		<description>How would you solve this without a switch?

&lt;pre lang="actionscript"&gt;
switch (overlayItem.dockSide)
{
	case DockSide.TOP:
		//put the item at the top
		break;
	case DockSide.BOTTOM:
		//put the item at the bottom
		break;
	case DockSide.LEFT:
		//put the item at the left
		break;
	case DockSide.RIGHT:
		//put the item at the right
		break;
};
&lt;/pre&gt;

Greetz Erik</description>
		<content:encoded><![CDATA[<p>How would you solve this without a switch?</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript"><span style="color: #b1b100;">switch</span> <span style="color: #66cc66;">&#40;</span>overlayItem.<span style="color: #006600;">dockSide</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #b1b100;">case</span> DockSide.<span style="color: #006600;">TOP</span>:
		<span style="color: #808080; font-style: italic;">//put the item at the top</span>
		<span style="color: #b1b100;">break</span>;
	<span style="color: #b1b100;">case</span> DockSide.<span style="color: #006600;">BOTTOM</span>:
		<span style="color: #808080; font-style: italic;">//put the item at the bottom</span>
		<span style="color: #b1b100;">break</span>;
	<span style="color: #b1b100;">case</span> DockSide.<span style="color: #0066CC;">LEFT</span>:
		<span style="color: #808080; font-style: italic;">//put the item at the left</span>
		<span style="color: #b1b100;">break</span>;
	<span style="color: #b1b100;">case</span> DockSide.<span style="color: #0066CC;">RIGHT</span>:
		<span style="color: #808080; font-style: italic;">//put the item at the right</span>
		<span style="color: #b1b100;">break</span>;
<span style="color: #66cc66;">&#125;</span>;</pre></div></div>

<p>Greetz Erik</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bill Sanders</title>
		<link>http://www.as3dp.com/2007/12/21/lets-get-rid-of-conditionals/#comment-546</link>
		<dc:creator>Bill Sanders</dc:creator>
		<pubDate>Tue, 25 Mar 2008 20:55:18 +0000</pubDate>
		<guid isPermaLink="false">http://www.as3dp.com/2007/12/21/lets-get-rid-of-conditionals/#comment-546</guid>
		<description>Hi William,

I admit that broaching the issue turned out to be heuristic, and so naturally I'm glad I did. To do justice to the author of the idea whom I met at OOPSLA, I probably should have set it up more clearly. However, the State Design Pattern is characterized by the lack of conditional statements. Instead, by selecting a context, all of the outcomes are already determined and so you don't need conditional statement.

After this exercise, though, I've got to admit that I'd be hard-pressed not to use conditional statements in most of the other design patterns. Chandima and I hope to continue pushing the envelope in this area, and everyone who's got an idea or a comment is always welcomed here. In the meantime, I'm trying to find time to get the next design pattern done!

Take care,
Bill</description>
		<content:encoded><![CDATA[<p>Hi William,</p>
<p>I admit that broaching the issue turned out to be heuristic, and so naturally I&#8217;m glad I did. To do justice to the author of the idea whom I met at OOPSLA, I probably should have set it up more clearly. However, the State Design Pattern is characterized by the lack of conditional statements. Instead, by selecting a context, all of the outcomes are already determined and so you don&#8217;t need conditional statement.</p>
<p>After this exercise, though, I&#8217;ve got to admit that I&#8217;d be hard-pressed not to use conditional statements in most of the other design patterns. Chandima and I hope to continue pushing the envelope in this area, and everyone who&#8217;s got an idea or a comment is always welcomed here. In the meantime, I&#8217;m trying to find time to get the next design pattern done!</p>
<p>Take care,<br />
Bill</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: William Bowers</title>
		<link>http://www.as3dp.com/2007/12/21/lets-get-rid-of-conditionals/#comment-544</link>
		<dc:creator>William Bowers</dc:creator>
		<pubDate>Tue, 25 Mar 2008 20:11:07 +0000</pubDate>
		<guid isPermaLink="false">http://www.as3dp.com/2007/12/21/lets-get-rid-of-conditionals/#comment-544</guid>
		<description>Ok, minus the loops :-D brain fart</description>
		<content:encoded><![CDATA[<p>Ok, minus the loops <img src='http://www.as3dp.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':-D' class='wp-smiley' /> brain fart</p>
]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.578 seconds -->
<!-- Cached page served by WP-Cache -->
