<?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: Design Pattern Principles for ActionScript 3.0: Favor Object Composition Over Class Inheritance</title>
	<atom:link href="http://www.as3dp.com/2009/02/21/design-pattern-principles-for-actionscript-30-favor-object-composition-over-class-inheritance/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.as3dp.com/2009/02/21/design-pattern-principles-for-actionscript-30-favor-object-composition-over-class-inheritance/</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: Add More Collectibles to Your AS3 Avoider Game &#124; Michael James Williams</title>
		<link>http://www.as3dp.com/2009/02/21/design-pattern-principles-for-actionscript-30-favor-object-composition-over-class-inheritance/comment-page-1/#comment-2209</link>
		<dc:creator>Add More Collectibles to Your AS3 Avoider Game &#124; Michael James Williams</dc:creator>
		<pubDate>Wed, 15 Apr 2009 02:19:50 +0000</pubDate>
		<guid isPermaLink="false">http://www.as3dp.com/?p=700#comment-2209</guid>
		<description>[...] this part of my Collectibles mini-series, we&#8217;ll favour object composition over class inheritance to add new types of coins in a much more flexible manner. Click the image below to try out the [...]</description>
		<content:encoded><![CDATA[<p>[...] this part of my Collectibles mini-series, we&#8217;ll favour object composition over class inheritance to add new types of coins in a much more flexible manner. Click the image below to try out the [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: William B. Sanders</title>
		<link>http://www.as3dp.com/2009/02/21/design-pattern-principles-for-actionscript-30-favor-object-composition-over-class-inheritance/comment-page-1/#comment-1730</link>
		<dc:creator>William B. Sanders</dc:creator>
		<pubDate>Mon, 02 Mar 2009 10:02:41 +0000</pubDate>
		<guid isPermaLink="false">http://www.as3dp.com/?p=700#comment-1730</guid>
		<description>Hi Drew,

I think that you&#039;ve expressed what a lot of developers experience concerning OOP and design patterns. It reminds me of the 17th Century poet Andrew Marvell&#039;s poem, &lt;em&gt;To his Coy Mistress&lt;/em&gt;

&lt;blockquote&gt;Had we but world enough, and time,
This coyness, lady, were no crime.
...
For, lady, you deserve this state,
Nor would I love at lower rate.

But at my back I always hear
Time&#039;s winged chariot hurrying near;....&lt;/blockquote&gt;

As all 17th Century literary scholars know, Marvell was really a Fortran I programmer (and did comic books on the side) and his coy mistress was a gig he had to get done &lt;em&gt;yesterday&lt;/em&gt;!

Ask yourself this:&lt;blockquote&gt;Is there &lt;em&gt;just one thing&lt;/em&gt; demonstrating good OOP or Design Patterns that I can do with this project?&lt;/blockquote&gt;

Now that you have the handy &lt;a href=&quot;http://poobah.mwd.hartford.edu/wsanders/principles/&quot; rel=&quot;nofollow&quot;&gt;Lunch Bucket Rules&lt;/a&gt; this shouldn&#039;t be as much of a problem as before. Nobody, and &lt;em&gt;I mean nobody&lt;/em&gt; is able to follow all of the OOP and design pattern rules all the time. However, being realistic, we need to start somewhere. Over time as we develop modules done using design patterns, we become more accustomed to doing it right. Let&#039;s face it, at some point we gave up sequential programming in favor of procedural programming, but it didn&#039;t happen all at once. Then, we gave up procedural programming for object oriented programming (OOP) and then started design patterns, and it&#039;s not going to happen all at once either. However, if we don&#039;t start someplace, it will never happen.

Take care,
Bill</description>
		<content:encoded><![CDATA[<p>Hi Drew,</p>
<p>I think that you&#8217;ve expressed what a lot of developers experience concerning OOP and design patterns. It reminds me of the 17th Century poet Andrew Marvell&#8217;s poem, <em>To his Coy Mistress</em></p>
<blockquote><p>Had we but world enough, and time,<br />
This coyness, lady, were no crime.<br />
&#8230;<br />
For, lady, you deserve this state,<br />
Nor would I love at lower rate.</p>
<p>But at my back I always hear<br />
Time&#8217;s winged chariot hurrying near;&#8230;.</p></blockquote>
<p>As all 17th Century literary scholars know, Marvell was really a Fortran I programmer (and did comic books on the side) and his coy mistress was a gig he had to get done <em>yesterday</em>!</p>
<p>Ask yourself this:<br />
<blockquote>Is there <em>just one thing</em> demonstrating good OOP or Design Patterns that I can do with this project?</p></blockquote>
<p>Now that you have the handy <a href="http://poobah.mwd.hartford.edu/wsanders/principles/" rel="nofollow">Lunch Bucket Rules</a> this shouldn&#8217;t be as much of a problem as before. Nobody, and <em>I mean nobody</em> is able to follow all of the OOP and design pattern rules all the time. However, being realistic, we need to start somewhere. Over time as we develop modules done using design patterns, we become more accustomed to doing it right. Let&#8217;s face it, at some point we gave up sequential programming in favor of procedural programming, but it didn&#8217;t happen all at once. Then, we gave up procedural programming for object oriented programming (OOP) and then started design patterns, and it&#8217;s not going to happen all at once either. However, if we don&#8217;t start someplace, it will never happen.</p>
<p>Take care,<br />
Bill</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: drew</title>
		<link>http://www.as3dp.com/2009/02/21/design-pattern-principles-for-actionscript-30-favor-object-composition-over-class-inheritance/comment-page-1/#comment-1728</link>
		<dc:creator>drew</dc:creator>
		<pubDate>Mon, 02 Mar 2009 03:35:53 +0000</pubDate>
		<guid isPermaLink="false">http://www.as3dp.com/?p=700#comment-1728</guid>
		<description>Hi,

For me it is really difficult to be observant of the right design especially if you are tied to short schedules. As a result I sometime find myself hoping that I could rewrite/redesign everything again though sadly there are always not enough time to recode.</description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>For me it is really difficult to be observant of the right design especially if you are tied to short schedules. As a result I sometime find myself hoping that I could rewrite/redesign everything again though sadly there are always not enough time to recode.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: localToGlobal &#187; Blog Archive &#187; news review -&#62; 8th week of 2009</title>
		<link>http://www.as3dp.com/2009/02/21/design-pattern-principles-for-actionscript-30-favor-object-composition-over-class-inheritance/comment-page-1/#comment-1705</link>
		<dc:creator>localToGlobal &#187; Blog Archive &#187; news review -&#62; 8th week of 2009</dc:creator>
		<pubDate>Wed, 25 Feb 2009 11:38:48 +0000</pubDate>
		<guid isPermaLink="false">http://www.as3dp.com/?p=700#comment-1705</guid>
		<description>[...] &gt; Favor Object Composition Over Class Inheritance &#124; ActionScript 3 Design Patterns [...]</description>
		<content:encoded><![CDATA[<p>[...] &gt; Favor Object Composition Over Class Inheritance | ActionScript 3 Design Patterns [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bill Sanders</title>
		<link>http://www.as3dp.com/2009/02/21/design-pattern-principles-for-actionscript-30-favor-object-composition-over-class-inheritance/comment-page-1/#comment-1688</link>
		<dc:creator>Bill Sanders</dc:creator>
		<pubDate>Mon, 23 Feb 2009 10:20:44 +0000</pubDate>
		<guid isPermaLink="false">http://www.as3dp.com/?p=700#comment-1688</guid>
		<description>Hi Sven,

Thanks for those kind words. I think that the most important discovery I made in this blog is that I&#039;m in the same boat as everyone else as far as immersing myself in good OOP. (Sounds like being dipped in a tasty pudding.) That is, I know about the principles, but too often I&#039;ll just put something together and worry about structure later. If things are really hectic, later never comes... Unfortunately, especially with smaller projects, everything works pretty well, and that&#039;s why bad habits (mine!) are so hard to break. I almost wish that any program I wrote NOT following good OOP would explode like a big bomb, singe my eyebrows, set my hair on fire and make the dog howl. Then the bad habits would be easy to break.

Lacking such a handy reminder as exploding programs, I set about to put all of the main DP and OOP principles in one place and in the form of good habits (this and the previous two posts on principles) and ways to help remind us what the principles mean--The Lunch Bucket Rules.

Like all principles, rules or guidelines, the first step is getting them all down pat. Once they become part of a mindset, then you can begin to find exceptions. Right now, though, I&#039;m trying to get them into a format where I can put them into an AIR application and have it handy. (See http://nemo.mwd.hartford.edu/~wsanders/lunchDP/ for the starting point--ideas welcomed!)

Thank you again for your insights,
Bill</description>
		<content:encoded><![CDATA[<p>Hi Sven,</p>
<p>Thanks for those kind words. I think that the most important discovery I made in this blog is that I&#8217;m in the same boat as everyone else as far as immersing myself in good OOP. (Sounds like being dipped in a tasty pudding.) That is, I know about the principles, but too often I&#8217;ll just put something together and worry about structure later. If things are really hectic, later never comes&#8230; Unfortunately, especially with smaller projects, everything works pretty well, and that&#8217;s why bad habits (mine!) are so hard to break. I almost wish that any program I wrote NOT following good OOP would explode like a big bomb, singe my eyebrows, set my hair on fire and make the dog howl. Then the bad habits would be easy to break.</p>
<p>Lacking such a handy reminder as exploding programs, I set about to put all of the main DP and OOP principles in one place and in the form of good habits (this and the previous two posts on principles) and ways to help remind us what the principles mean&#8211;The Lunch Bucket Rules.</p>
<p>Like all principles, rules or guidelines, the first step is getting them all down pat. Once they become part of a mindset, then you can begin to find exceptions. Right now, though, I&#8217;m trying to get them into a format where I can put them into an AIR application and have it handy. (See <a href="http://nemo.mwd.hartford.edu/~wsanders/lunchDP/" rel="nofollow">http://nemo.mwd.hartford.edu/~wsanders/lunchDP/</a> for the starting point&#8211;ideas welcomed!)</p>
<p>Thank you again for your insights,<br />
Bill</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sven</title>
		<link>http://www.as3dp.com/2009/02/21/design-pattern-principles-for-actionscript-30-favor-object-composition-over-class-inheritance/comment-page-1/#comment-1686</link>
		<dc:creator>Sven</dc:creator>
		<pubDate>Mon, 23 Feb 2009 08:56:25 +0000</pubDate>
		<guid isPermaLink="false">http://www.as3dp.com/?p=700#comment-1686</guid>
		<description>Hi Bill,

agreed. I see, we&#039;re on the same track. I guess, what i wanted to express was, by explaining the specific scenarios, in which inheritance makes sense (as you seem to have done in you book, sorry haven&#039;t read it yet, will do so asap) and presenting those in contrast to the scenarios, in which it doesn&#039;t make sense and principles like composition are more suitable, developers might understand the pros and cons better and will more likely choose it more wisely.

And to your first paragraph: I am aware, that you are quoting other people in your posts. But it would be boring, to simply read quotes on this blog. So what makes reading this blog interesting, is the combination of those quotes and your very own experience and the way, you look on those things. Otherwise, i could simply buy the book from the GoF (if i hadn&#039;t already done so). So, go on, take the risk of expressing things in your own words, i&#039;m sure, that&#039;s what keeps people reading your stuff.</description>
		<content:encoded><![CDATA[<p>Hi Bill,</p>
<p>agreed. I see, we&#8217;re on the same track. I guess, what i wanted to express was, by explaining the specific scenarios, in which inheritance makes sense (as you seem to have done in you book, sorry haven&#8217;t read it yet, will do so asap) and presenting those in contrast to the scenarios, in which it doesn&#8217;t make sense and principles like composition are more suitable, developers might understand the pros and cons better and will more likely choose it more wisely.</p>
<p>And to your first paragraph: I am aware, that you are quoting other people in your posts. But it would be boring, to simply read quotes on this blog. So what makes reading this blog interesting, is the combination of those quotes and your very own experience and the way, you look on those things. Otherwise, i could simply buy the book from the GoF (if i hadn&#8217;t already done so). So, go on, take the risk of expressing things in your own words, i&#8217;m sure, that&#8217;s what keeps people reading your stuff.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bill Sanders</title>
		<link>http://www.as3dp.com/2009/02/21/design-pattern-principles-for-actionscript-30-favor-object-composition-over-class-inheritance/comment-page-1/#comment-1680</link>
		<dc:creator>Bill Sanders</dc:creator>
		<pubDate>Sun, 22 Feb 2009 12:00:23 +0000</pubDate>
		<guid isPermaLink="false">http://www.as3dp.com/?p=700#comment-1680</guid>
		<description>Hi Sven,

When I write a post about a &lt;strong&gt;principle&lt;/strong&gt; you can assume that &lt;em&gt;it is &lt;strong&gt;not&lt;/strong&gt; my principle&lt;/em&gt; but rather one from OOP or design patterns. I agree with the principles, but I am certainly not their author. Most are from GoF but you will find others from different sources, such as Barbara Liskov. So when readers say to me, &lt;em&gt;...your principles...&lt;/em&gt; or &lt;em&gt;...you are saying...&lt;/em&gt; I feel uneasy. I&#039;m not claiming to be &lt;em&gt;just the messenger&lt;/em&gt; because I fully support these principles. Rather, I am hoping readers of this blog will think about these principles in terms of the very smart people who developed them and not some wild hair I concocted.

As you saw reading the entire post, the Gang of Four do not rule out using inheritance. Rather, they say that when you&#039;re writing a program--and they&#039;re thinking of big programs, not a simple &lt;strong&gt;gotoAndStop()&lt;/strong&gt; one—you should think about it in terms of composition and &lt;strong&gt;not&lt;/strong&gt; a hierarchy. Further, as you noted, the message is to keep the hierarchies shallow and the base classes abstract.

One of the best examples of where you can clearly see composition at work with inheritance is the &lt;a href=&quot;http://www.as3dp.com/2009/01/25/actionscript-30-abstract-factory-design-pattern-multiple-products-and-factories/&quot; rel=&quot;nofollow&quot;&gt;Abstract Factory Pattern&lt;/a&gt;. There you will see all these little hierarchies with the Client holding a reference to abstract classes and composing a solution rather than relying on a single hierarchy. Thus, you have both programming to an interface instead of an implementation &lt;em&gt;and&lt;/em&gt; and favoring composition over inheritance.

I&#039;d like to agree with you and say if you&#039;re really careful with hierarchies using private, protected and final access statements that everything will be dandy. I cannot say that. Rather, I&#039;m saying we (not &lt;em&gt;you&lt;/em&gt;, but &lt;strong&gt;we&lt;/strong&gt;) need to evaluate how we use inheritance in our programs, and scale them back. Instead of adding another class or method, we need to consider adding another component to the framework to handle an added functionally.

When we do use hierarchies we need to consider design patterns that make use of them and examine exactly what&#039;s going on. One of my favorite design patterns is the Template Method (Chapter 9 in our book). Your query is addressed in the section &quot;Why Inheritance and Not Composition?&quot; on page 335. It points out that there are indeed situations where inheritance is the way to go; so neither GoF nor we are dogmatic about inheritance.

However, let me hark back to the original point, &lt;em&gt;favor composition over class inheritance&lt;/em&gt;. For the most part, it does say, don&#039;t depend on inheritance to solve your programming problems. If you do, you&#039;re likely to run into dependency problems, broken encapsulation, and a whole host of other problems.

Like everyone else who&#039;s been programming for over 30 years, I like to think I know what I&#039;m doing, but the fact of the matter is that I&#039;ve had more time to build up some pretty bad habits. As programming languages change and evolve, as ActionScript 3.0 has, I need to re-think everything, and I have found that design patterns provide a way to kick me out of some of these habits. Favoring composition over class inheritance is a good habit I want to adopt, and it means that deep hierarchies need to be dumped.

Kindest regards,
Bill</description>
		<content:encoded><![CDATA[<p>Hi Sven,</p>
<p>When I write a post about a <strong>principle</strong> you can assume that <em>it is <strong>not</strong> my principle</em> but rather one from OOP or design patterns. I agree with the principles, but I am certainly not their author. Most are from GoF but you will find others from different sources, such as Barbara Liskov. So when readers say to me, <em>&#8230;your principles&#8230;</em> or <em>&#8230;you are saying&#8230;</em> I feel uneasy. I&#8217;m not claiming to be <em>just the messenger</em> because I fully support these principles. Rather, I am hoping readers of this blog will think about these principles in terms of the very smart people who developed them and not some wild hair I concocted.</p>
<p>As you saw reading the entire post, the Gang of Four do not rule out using inheritance. Rather, they say that when you&#8217;re writing a program&#8211;and they&#8217;re thinking of big programs, not a simple <strong>gotoAndStop()</strong> one—you should think about it in terms of composition and <strong>not</strong> a hierarchy. Further, as you noted, the message is to keep the hierarchies shallow and the base classes abstract.</p>
<p>One of the best examples of where you can clearly see composition at work with inheritance is the <a href="http://www.as3dp.com/2009/01/25/actionscript-30-abstract-factory-design-pattern-multiple-products-and-factories/" rel="nofollow">Abstract Factory Pattern</a>. There you will see all these little hierarchies with the Client holding a reference to abstract classes and composing a solution rather than relying on a single hierarchy. Thus, you have both programming to an interface instead of an implementation <em>and</em> and favoring composition over inheritance.</p>
<p>I&#8217;d like to agree with you and say if you&#8217;re really careful with hierarchies using private, protected and final access statements that everything will be dandy. I cannot say that. Rather, I&#8217;m saying we (not <em>you</em>, but <strong>we</strong>) need to evaluate how we use inheritance in our programs, and scale them back. Instead of adding another class or method, we need to consider adding another component to the framework to handle an added functionally.</p>
<p>When we do use hierarchies we need to consider design patterns that make use of them and examine exactly what&#8217;s going on. One of my favorite design patterns is the Template Method (Chapter 9 in our book). Your query is addressed in the section &#8220;Why Inheritance and Not Composition?&#8221; on page 335. It points out that there are indeed situations where inheritance is the way to go; so neither GoF nor we are dogmatic about inheritance.</p>
<p>However, let me hark back to the original point, <em>favor composition over class inheritance</em>. For the most part, it does say, don&#8217;t depend on inheritance to solve your programming problems. If you do, you&#8217;re likely to run into dependency problems, broken encapsulation, and a whole host of other problems.</p>
<p>Like everyone else who&#8217;s been programming for over 30 years, I like to think I know what I&#8217;m doing, but the fact of the matter is that I&#8217;ve had more time to build up some pretty bad habits. As programming languages change and evolve, as ActionScript 3.0 has, I need to re-think everything, and I have found that design patterns provide a way to kick me out of some of these habits. Favoring composition over class inheritance is a good habit I want to adopt, and it means that deep hierarchies need to be dumped.</p>
<p>Kindest regards,<br />
Bill</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sven</title>
		<link>http://www.as3dp.com/2009/02/21/design-pattern-principles-for-actionscript-30-favor-object-composition-over-class-inheritance/comment-page-1/#comment-1674</link>
		<dc:creator>Sven</dc:creator>
		<pubDate>Sat, 21 Feb 2009 20:50:35 +0000</pubDate>
		<guid isPermaLink="false">http://www.as3dp.com/?p=700#comment-1674</guid>
		<description>Hi,

i like the article. In the end, i think you&#039;re not really proposing to NOT to use inheritance, but simply to avoid using deep inheritance hierarchies, which i totally agree with. You giving arguments for composition in favor of inheritance, but i would also like to see arguments for using inheritance and when it makes sense.

For example, building abstraction with types and subtypes is clearly something, you&#039;ll want to use inheritance for. As Barbara Liskov stated, you should favor type inheritance over implementation inheritance and i think that nails it. If you want to make clear, that a specific type is related to a more general type, then inheritance is the way to go. If you are simply seeking for reusing as much code as possible, composition will be more suitable in many situations.

One last word to encapsulation within inheritance hierarchies. I would like to say, that inheritance does not automatically mean strong coupling. You can achieve quite some loose coupling between a super- and a subclass, if you use protected and private wisely as well as final. In that sense i see inheritance simply as another kind of association between two classes. You will always want to control visibility and encapsulation between classes and you should do so within inherited classes, too.</description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>i like the article. In the end, i think you&#8217;re not really proposing to NOT to use inheritance, but simply to avoid using deep inheritance hierarchies, which i totally agree with. You giving arguments for composition in favor of inheritance, but i would also like to see arguments for using inheritance and when it makes sense.</p>
<p>For example, building abstraction with types and subtypes is clearly something, you&#8217;ll want to use inheritance for. As Barbara Liskov stated, you should favor type inheritance over implementation inheritance and i think that nails it. If you want to make clear, that a specific type is related to a more general type, then inheritance is the way to go. If you are simply seeking for reusing as much code as possible, composition will be more suitable in many situations.</p>
<p>One last word to encapsulation within inheritance hierarchies. I would like to say, that inheritance does not automatically mean strong coupling. You can achieve quite some loose coupling between a super- and a subclass, if you use protected and private wisely as well as final. In that sense i see inheritance simply as another kind of association between two classes. You will always want to control visibility and encapsulation between classes and you should do so within inherited classes, too.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
