<?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"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule"
	>
<channel>
	<title>Comments on: Wrong Way Warrior: Getting Flexibility with Design Patterns—Part II</title>
	<atom:link href="http://www.as3dp.com/2009/08/19/wrong-way-warrior-getting-flexibility-with-design-patterns%e2%80%94part-ii/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.as3dp.com/2009/08/19/wrong-way-warrior-getting-flexibility-with-design-patterns%e2%80%94part-ii/</link>
	<description>OOP Techniques for Flash and Flex Developers</description>
	<lastBuildDate>Mon, 26 Jul 2010 13:40:37 -0700</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: William B. Sanders</title>
		<link>http://www.as3dp.com/2009/08/19/wrong-way-warrior-getting-flexibility-with-design-patterns%e2%80%94part-ii/comment-page-1/#comment-2841</link>
		<dc:creator>William B. Sanders</dc:creator>
		<pubDate>Wed, 26 Aug 2009 12:59:38 +0000</pubDate>
		<guid isPermaLink="false">http://www.as3dp.com/?p=1304#comment-2841</guid>
		<description>Hi Xixixao,

Most of the questions you&#039;re asking are handled in Chapter 1; so if I miss something, you can probably find it there. In both OOP and Design Patterns, there are no simple explanations that will cover everything; especially the good questions that you are asking, and so I&#039;ll also have some links to other posts on this blog that will help out. If you haven&#039;t done so already, download the &lt;a href=&quot;http://www.as3dp.com/2009/02/26/oop-designs-pattern-principles-ready-for-work/&quot; rel=&quot;nofollow&quot;&gt;AIR app&lt;/a&gt; with all of the major design pattern principles. The principles make up the bulk of the &quot;whys&quot;—each of the principles is discussed in detail, and you can find them all in the &lt;a href=&quot;http://www.as3dp.com/category/index/&quot; rel=&quot;nofollow&quot;&gt;Index&lt;/a&gt; of this blog. The AIR app is just a handy reminder of them that you can put on your desktop.

The simple answer for using the &lt;strong&gt;private&lt;/strong&gt; accessor is to encapsulate properties or functions. In this particular case, the OOP programmer wants to use the MovieClip in the Library. However, he just needs the image aspects of it; so he types it as the parent class, Sprite. Had he needed to use timeline methods, he would have typed it as a MovieClip. His Warrior class provides a set of behaviors (methods) for all warriors; but to have flexibility, the Warrior class does not include images. Therefore, the developer can subclass the Warrior and then add sprites that provide a visual representation—in this case the Red and Blue warriors.

As for keeping track of the x and y values in the positions, you&#039;re right. It doesn&#039;t do that. All this example is doing is setting up a straw man (of sorts) to show how this approach (even though using OOP) will fail as soon as more behaviors are added. In Part II here, you see that there&#039;s no movement at all. Instead, using a &lt;a href=&quot;http://www.as3dp.com/2009/03/08/actionscript-30-easy-and-practical-strategy-design-pattern/&quot; rel=&quot;nofollow&quot;&gt;Strategy design pattern&lt;/a&gt;, the behaviors are encapsulated in a separate set of classes around a common interface (Fire).

However, you will notice that a couple of commented-out statements hint to the possibility of encapsulating both movement and communication. The latest &lt;a href=&quot;http://www.as3dp.com/2009/08/24/golden-lunch-bucket-contest-4-extending-the-warrior/&quot; rel=&quot;nofollow&quot;&gt;Golden Lunch Bucket Contest&lt;/a&gt; also shows these tantalizing possibilities. You can create any kind of movement you want by setting up a Movement interface (either as an abstract class or interface) and then using composition, have your warriors move as you like. As you say, the way to go &lt;em&gt;may be&lt;/em&gt; with an array. Why not try it out with your ideas and enter the contest? Later, you and KKCosmo can implement the Communication interface and have the Lieutenant bark orders that will set the platoon in motion! (Give the Lieutenant that redneck accent that Brad Pitt uses in &lt;em&gt;Inglourious Basterds&lt;/em&gt;.)

Kindest regards,
Bill</description>
		<content:encoded><![CDATA[<p>Hi Xixixao,</p>
<p>Most of the questions you&#8217;re asking are handled in Chapter 1; so if I miss something, you can probably find it there. In both OOP and Design Patterns, there are no simple explanations that will cover everything; especially the good questions that you are asking, and so I&#8217;ll also have some links to other posts on this blog that will help out. If you haven&#8217;t done so already, download the <a href="http://www.as3dp.com/2009/02/26/oop-designs-pattern-principles-ready-for-work/" rel="nofollow">AIR app</a> with all of the major design pattern principles. The principles make up the bulk of the &#8220;whys&#8221;—each of the principles is discussed in detail, and you can find them all in the <a href="http://www.as3dp.com/category/index/" rel="nofollow">Index</a> of this blog. The AIR app is just a handy reminder of them that you can put on your desktop.</p>
<p>The simple answer for using the <strong>private</strong> accessor is to encapsulate properties or functions. In this particular case, the OOP programmer wants to use the MovieClip in the Library. However, he just needs the image aspects of it; so he types it as the parent class, Sprite. Had he needed to use timeline methods, he would have typed it as a MovieClip. His Warrior class provides a set of behaviors (methods) for all warriors; but to have flexibility, the Warrior class does not include images. Therefore, the developer can subclass the Warrior and then add sprites that provide a visual representation—in this case the Red and Blue warriors.</p>
<p>As for keeping track of the x and y values in the positions, you&#8217;re right. It doesn&#8217;t do that. All this example is doing is setting up a straw man (of sorts) to show how this approach (even though using OOP) will fail as soon as more behaviors are added. In Part II here, you see that there&#8217;s no movement at all. Instead, using a <a href="http://www.as3dp.com/2009/03/08/actionscript-30-easy-and-practical-strategy-design-pattern/" rel="nofollow">Strategy design pattern</a>, the behaviors are encapsulated in a separate set of classes around a common interface (Fire).</p>
<p>However, you will notice that a couple of commented-out statements hint to the possibility of encapsulating both movement and communication. The latest <a href="http://www.as3dp.com/2009/08/24/golden-lunch-bucket-contest-4-extending-the-warrior/" rel="nofollow">Golden Lunch Bucket Contest</a> also shows these tantalizing possibilities. You can create any kind of movement you want by setting up a Movement interface (either as an abstract class or interface) and then using composition, have your warriors move as you like. As you say, the way to go <em>may be</em> with an array. Why not try it out with your ideas and enter the contest? Later, you and KKCosmo can implement the Communication interface and have the Lieutenant bark orders that will set the platoon in motion! (Give the Lieutenant that redneck accent that Brad Pitt uses in <em>Inglourious Basterds</em>.)</p>
<p>Kindest regards,<br />
Bill</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: xixixao</title>
		<link>http://www.as3dp.com/2009/08/19/wrong-way-warrior-getting-flexibility-with-design-patterns%e2%80%94part-ii/comment-page-1/#comment-2839</link>
		<dc:creator>xixixao</dc:creator>
		<pubDate>Wed, 26 Aug 2009 10:06:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.as3dp.com/?p=1304#comment-2839</guid>
		<description>Hi,
first of all thank for all of your work ;). Second of all, I just started with OOP in AS3 and flash couple months ago. Ive got several questions. For example, you are putting (and as I understood it, its a good practice) the &quot;sprite&quot; from library, RedWarrior for example, into private var of another class. Why? :) I could probably find the answer somewhere here, so important question. You are positioning this &quot;sprite&quot; inside of the new class. So then, as I usually do, you are not able to keep track of xs and ys of all of yours soldiers. Also using private vars (in Client class) for every soldier seems so clumsy (and it takes so much space), and it seems like you are using it only for removing those soldiers (which could be done, in my opinion, more easily, either with sets of arrays or with holder sprites). I am probably all wrong, but these are the things that came to my mind when I read this.
P.S.: And I totally agree with KKCosmo :).

Be well.</description>
		<content:encoded><![CDATA[<p>Hi,<br />
first of all thank for all of your work ;). Second of all, I just started with OOP in AS3 and flash couple months ago. Ive got several questions. For example, you are putting (and as I understood it, its a good practice) the &#8220;sprite&#8221; from library, RedWarrior for example, into private var of another class. Why? :) I could probably find the answer somewhere here, so important question. You are positioning this &#8220;sprite&#8221; inside of the new class. So then, as I usually do, you are not able to keep track of xs and ys of all of yours soldiers. Also using private vars (in Client class) for every soldier seems so clumsy (and it takes so much space), and it seems like you are using it only for removing those soldiers (which could be done, in my opinion, more easily, either with sets of arrays or with holder sprites). I am probably all wrong, but these are the things that came to my mind when I read this.<br />
P.S.: And I totally agree with KKCosmo :).</p>
<p>Be well.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: William B. Sanders</title>
		<link>http://www.as3dp.com/2009/08/19/wrong-way-warrior-getting-flexibility-with-design-patterns%e2%80%94part-ii/comment-page-1/#comment-2819</link>
		<dc:creator>William B. Sanders</dc:creator>
		<pubDate>Thu, 20 Aug 2009 20:40:46 +0000</pubDate>
		<guid isPermaLink="false">http://www.as3dp.com/?p=1304#comment-2819</guid>
		<description>Hi T,

This is all about extending existing programs; so you can make it anything you want. Why not start with something simple?

Take care,
Bill</description>
		<content:encoded><![CDATA[<p>Hi T,</p>
<p>This is all about extending existing programs; so you can make it anything you want. Why not start with something simple?</p>
<p>Take care,<br />
Bill</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: T</title>
		<link>http://www.as3dp.com/2009/08/19/wrong-way-warrior-getting-flexibility-with-design-patterns%e2%80%94part-ii/comment-page-1/#comment-2817</link>
		<dc:creator>T</dc:creator>
		<pubDate>Thu, 20 Aug 2009 19:03:51 +0000</pubDate>
		<guid isPermaLink="false">http://www.as3dp.com/?p=1304#comment-2817</guid>
		<description>assuming that this demo game will eventually have two sides (blue vs red, etc.), it would be cool to see the implementation of a new &quot;Spy&quot; class, which would basically extend the Warrior class (and the Warrior class would use composition to assign both FireBehavior and WarriorBehavior).</description>
		<content:encoded><![CDATA[<p>assuming that this demo game will eventually have two sides (blue vs red, etc.), it would be cool to see the implementation of a new &#8220;Spy&#8221; class, which would basically extend the Warrior class (and the Warrior class would use composition to assign both FireBehavior and WarriorBehavior).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: William B. Sanders</title>
		<link>http://www.as3dp.com/2009/08/19/wrong-way-warrior-getting-flexibility-with-design-patterns%e2%80%94part-ii/comment-page-1/#comment-2814</link>
		<dc:creator>William B. Sanders</dc:creator>
		<pubDate>Thu, 20 Aug 2009 12:45:29 +0000</pubDate>
		<guid isPermaLink="false">http://www.as3dp.com/?p=1304#comment-2814</guid>
		<description>Hi T,

Glad to hear it. As for suggestions, let&#039;s see something a bit more... Maybe you can add a light mortar crew... I realize they&#039;re not part of the platoon TOE, but we&#039;ll pretend that the platoon receive a light mortar crew (3 members) to provide added defense against an attack by hordes of Unencapsulated Code Zombies. (How&#039;s that for motivation?) Check out:
http://www.jhu.edu/rotc/Basic_Army_Knowledge/Military_Symbols.htm
for a military symbol for mortars.

Cheers,
Bill</description>
		<content:encoded><![CDATA[<p>Hi T,</p>
<p>Glad to hear it. As for suggestions, let&#8217;s see something a bit more&#8230; Maybe you can add a light mortar crew&#8230; I realize they&#8217;re not part of the platoon TOE, but we&#8217;ll pretend that the platoon receive a light mortar crew (3 members) to provide added defense against an attack by hordes of Unencapsulated Code Zombies. (How&#8217;s that for motivation?) Check out:<br />
<a href="http://www.jhu.edu/rotc/Basic_Army_Knowledge/Military_Symbols.htm" rel="nofollow">http://www.jhu.edu/rotc/Basic_Army_Knowledge/Military_Symbols.htm</a><br />
for a military symbol for mortars.</p>
<p>Cheers,<br />
Bill</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: T</title>
		<link>http://www.as3dp.com/2009/08/19/wrong-way-warrior-getting-flexibility-with-design-patterns%e2%80%94part-ii/comment-page-1/#comment-2813</link>
		<dc:creator>T</dc:creator>
		<pubDate>Thu, 20 Aug 2009 12:25:36 +0000</pubDate>
		<guid isPermaLink="false">http://www.as3dp.com/?p=1304#comment-2813</guid>
		<description>Bill, how delighted I was to see the followup article posted so quickly!  I&#039;ll have a few suggestions for where the app should go next after I get a chance to soak this all in...</description>
		<content:encoded><![CDATA[<p>Bill, how delighted I was to see the followup article posted so quickly!  I&#8217;ll have a few suggestions for where the app should go next after I get a chance to soak this all in&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: William B. Sanders</title>
		<link>http://www.as3dp.com/2009/08/19/wrong-way-warrior-getting-flexibility-with-design-patterns%e2%80%94part-ii/comment-page-1/#comment-2811</link>
		<dc:creator>William B. Sanders</dc:creator>
		<pubDate>Thu, 20 Aug 2009 09:05:17 +0000</pubDate>
		<guid isPermaLink="false">http://www.as3dp.com/?p=1304#comment-2811</guid>
		<description>Hi KKCosma,

Yeah, the Lieutenant sounds like Rambo on steroids. Actually, the sounds from the Team Leaders, Squad Leaders, Platoon Sergeant and Lieutenant represent the unit firing on a command. Of course, we might want to think about the addition of a class that would handle different commands. How would be go about that, and instead of a booming sound of all of the platoon&#039;s weapons going off at once, we&#039;d hear a command to that effect and all of the weapons would then sound off? Something like, &quot;We&#039;re being attacked by Sequential Programmers! Blast &#039;em!&quot; -- then we&#039;d hear a platoon firing sound.

Cheers,
Bill</description>
		<content:encoded><![CDATA[<p>Hi KKCosma,</p>
<p>Yeah, the Lieutenant sounds like Rambo on steroids. Actually, the sounds from the Team Leaders, Squad Leaders, Platoon Sergeant and Lieutenant represent the unit firing on a command. Of course, we might want to think about the addition of a class that would handle different commands. How would be go about that, and instead of a booming sound of all of the platoon&#8217;s weapons going off at once, we&#8217;d hear a command to that effect and all of the weapons would then sound off? Something like, &#8220;We&#8217;re being attacked by Sequential Programmers! Blast &#8216;em!&#8221; &#8212; then we&#8217;d hear a platoon firing sound.</p>
<p>Cheers,<br />
Bill</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: KKCosmo</title>
		<link>http://www.as3dp.com/2009/08/19/wrong-way-warrior-getting-flexibility-with-design-patterns%e2%80%94part-ii/comment-page-1/#comment-2810</link>
		<dc:creator>KKCosmo</dc:creator>
		<pubDate>Thu, 20 Aug 2009 07:04:12 +0000</pubDate>
		<guid isPermaLink="false">http://www.as3dp.com/?p=1304#comment-2810</guid>
		<description>I hope the Lieutenant will learn to shout a command to let his troops fire, instead of firing all by himself.</description>
		<content:encoded><![CDATA[<p>I hope the Lieutenant will learn to shout a command to let his troops fire, instead of firing all by himself.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: William B. Sanders</title>
		<link>http://www.as3dp.com/2009/08/19/wrong-way-warrior-getting-flexibility-with-design-patterns%e2%80%94part-ii/comment-page-1/#comment-2809</link>
		<dc:creator>William B. Sanders</dc:creator>
		<pubDate>Thu, 20 Aug 2009 00:35:21 +0000</pubDate>
		<guid isPermaLink="false">http://www.as3dp.com/?p=1304#comment-2809</guid>
		<description>Hi Sean,

Chandima and I are glad to hear it. We&#039;re also looking for new ideas. Where do you think this application should go next?

Kindest regards,
Bill</description>
		<content:encoded><![CDATA[<p>Hi Sean,</p>
<p>Chandima and I are glad to hear it. We&#8217;re also looking for new ideas. Where do you think this application should go next?</p>
<p>Kindest regards,<br />
Bill</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sean</title>
		<link>http://www.as3dp.com/2009/08/19/wrong-way-warrior-getting-flexibility-with-design-patterns%e2%80%94part-ii/comment-page-1/#comment-2808</link>
		<dc:creator>Sean</dc:creator>
		<pubDate>Wed, 19 Aug 2009 21:45:59 +0000</pubDate>
		<guid isPermaLink="false">http://www.as3dp.com/?p=1304#comment-2808</guid>
		<description>Nice work!! Learning a whole lot here.</description>
		<content:encoded><![CDATA[<p>Nice work!! Learning a whole lot here.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
