<?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: Composite Pattern: Extending the Book to include Composite Pages (Part II)</title>
	<atom:link href="http://www.as3dp.com/2007/08/05/composite-pattern-extending-the-book-to-add-composite-pages-part-ii/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.as3dp.com/2007/08/05/composite-pattern-extending-the-book-to-add-composite-pages-part-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: Ben</title>
		<link>http://www.as3dp.com/2007/08/05/composite-pattern-extending-the-book-to-add-composite-pages-part-ii/comment-page-1/#comment-3893</link>
		<dc:creator>Ben</dc:creator>
		<pubDate>Sat, 23 Jan 2010 14:28:17 +0000</pubDate>
		<guid isPermaLink="false">http://www.as3dp.com/2007/08/06/composite-pattern-extending-the-book-to-add-composite-pages-part-ii/#comment-3893</guid>
		<description>Hi there

I&#039;m using the composite pattern for a Flex app.  I&#039;m drawing a series of nodes which are connected to one another (it represents a flow diagram).  In the requirement, nodes have children but those children can also be parents of the node.  How would I achieve something like this. Have you come across any examples?  Maybe I&#039;m approaching it wrong altogether.  Maybe there should only be a parent/child relationship and there should be some other mechanism to achieve this relationship?

Ben</description>
		<content:encoded><![CDATA[<p>Hi there</p>
<p>I&#8217;m using the composite pattern for a Flex app.  I&#8217;m drawing a series of nodes which are connected to one another (it represents a flow diagram).  In the requirement, nodes have children but those children can also be parents of the node.  How would I achieve something like this. Have you come across any examples?  Maybe I&#8217;m approaching it wrong altogether.  Maybe there should only be a parent/child relationship and there should be some other mechanism to achieve this relationship?</p>
<p>Ben</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Fabian</title>
		<link>http://www.as3dp.com/2007/08/05/composite-pattern-extending-the-book-to-add-composite-pages-part-ii/comment-page-1/#comment-757</link>
		<dc:creator>Fabian</dc:creator>
		<pubDate>Sun, 21 Sep 2008 12:07:15 +0000</pubDate>
		<guid isPermaLink="false">http://www.as3dp.com/2007/08/06/composite-pattern-extending-the-book-to-add-composite-pages-part-ii/#comment-757</guid>
		<description>I was wondering if its possible to combine this pattern with the Iterator-Pattern.

Advantage: You can go through the whole objects of the objekt-tree, e.g. to get just one sort ob objects.

I found a java-example in the head-first dp&lt;book. But i have no idea how do this in action-script. There a lot of recursive stuff, and they work with the java-build-in-iteraor ;-(</description>
		<content:encoded><![CDATA[<p>I was wondering if its possible to combine this pattern with the Iterator-Pattern.</p>
<p>Advantage: You can go through the whole objects of the objekt-tree, e.g. to get just one sort ob objects.</p>
<p>I found a java-example in the head-first dp&lt;book. But i have no idea how do this in action-script. There a lot of recursive stuff, and they work with the java-build-in-iteraor ;-(</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: chandima</title>
		<link>http://www.as3dp.com/2007/08/05/composite-pattern-extending-the-book-to-add-composite-pages-part-ii/comment-page-1/#comment-630</link>
		<dc:creator>chandima</dc:creator>
		<pubDate>Tue, 10 Jun 2008 03:22:21 +0000</pubDate>
		<guid isPermaLink="false">http://www.as3dp.com/2007/08/06/composite-pattern-extending-the-book-to-add-composite-pages-part-ii/#comment-630</guid>
		<description>Hi CG, try executing the &lt;code&gt;removeChild&lt;/code&gt; before splicing the component from the _cvChildren array because there is a chance that &#039;cv&#039; can get garbage collected as soon as it is spliced. The following sequence inside the loop should work:

&lt;pre lang=&quot;actionscript&quot;&gt;
removeChild(cv);
trace(&quot;removed component: &quot; + cv);
_cvChildren.splice(i,1);
break;
&lt;/pre&gt;

You are correct. Simply removing the composite should suffice for garbage collection, as long as there are no external references to any of its child components.</description>
		<content:encoded><![CDATA[<p>Hi CG, try executing the <code>removeChild</code> before splicing the component from the _cvChildren array because there is a chance that &#8216;cv&#8217; can get garbage collected as soon as it is spliced. The following sequence inside the loop should work:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p31code1'); return false;">View Code</a> ACTIONSCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p311"><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code" id="p31code1"><pre class="actionscript" style="font-family:monospace;">removeChild<span style="color: #66cc66;">&#40;</span>cv<span style="color: #66cc66;">&#41;</span>;
<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;removed component: &quot;</span> + cv<span style="color: #66cc66;">&#41;</span>;
_cvChildren.<span style="color: #0066CC;">splice</span><span style="color: #66cc66;">&#40;</span>i,<span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #b1b100;">break</span>;</pre></td></tr></table></div>

<p>You are correct. Simply removing the composite should suffice for garbage collection, as long as there are no external references to any of its child components.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: CG</title>
		<link>http://www.as3dp.com/2007/08/05/composite-pattern-extending-the-book-to-add-composite-pages-part-ii/comment-page-1/#comment-629</link>
		<dc:creator>CG</dc:creator>
		<pubDate>Sat, 07 Jun 2008 11:44:12 +0000</pubDate>
		<guid isPermaLink="false">http://www.as3dp.com/2007/08/06/composite-pattern-extending-the-book-to-add-composite-pages-part-ii/#comment-629</guid>
		<description>This book is superb!!

How would I remove a single, specific component from a composite?  This is the closest I&#039;ve come:

&lt;pre lang=&quot;actionscript&quot;&gt;
override public function remove(cv:CountryComponent):void {
	for (var i:uint=0; i &lt; _cvChildren.length; i++) {
		if (_cvChildren[i] == cv) {
			_cvChildren.splice(i,1);
			removeChild(cv);
			trace(&quot;removed component: &quot; + cv);
		}
	}
}&lt;/pre&gt;

Also - re: your last reply, if we want to implement a &quot;remove all&quot; we can just remove the composite, correct?  or do I have to script a removeAll that loops through _cvChildren and runs remove() for each component?</description>
		<content:encoded><![CDATA[<p>This book is superb!!</p>
<p>How would I remove a single, specific component from a composite?  This is the closest I&#8217;ve come:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p31code2'); return false;">View Code</a> ACTIONSCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p312"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code" id="p31code2"><pre class="actionscript" style="font-family:monospace;">override <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> remove<span style="color: #66cc66;">&#40;</span>cv:CountryComponent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
	<span style="color: #b1b100;">for</span> <span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">var</span> i:uint=<span style="color: #cc66cc;">0</span>; i <span style="color: #66cc66;">&lt;</span> _cvChildren.<span style="color: #0066CC;">length</span>; i++<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>_cvChildren<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span> == cv<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
			_cvChildren.<span style="color: #0066CC;">splice</span><span style="color: #66cc66;">&#40;</span>i,<span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span>;
			removeChild<span style="color: #66cc66;">&#40;</span>cv<span style="color: #66cc66;">&#41;</span>;
			<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;removed component: &quot;</span> + cv<span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p>Also &#8211; re: your last reply, if we want to implement a &#8220;remove all&#8221; we can just remove the composite, correct?  or do I have to script a removeAll that loops through _cvChildren and runs remove() for each component?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: chandima</title>
		<link>http://www.as3dp.com/2007/08/05/composite-pattern-extending-the-book-to-add-composite-pages-part-ii/comment-page-1/#comment-576</link>
		<dc:creator>chandima</dc:creator>
		<pubDate>Fri, 25 Apr 2008 20:28:15 +0000</pubDate>
		<guid isPermaLink="false">http://www.as3dp.com/2007/08/06/composite-pattern-extending-the-book-to-add-composite-pages-part-ii/#comment-576</guid>
		<description>Hi Ted, quite an interesting question. I think that one would implement a true component to intentionally prevent it from having any children. If you are not quite sure, then all nodes should probably be composites.

A good example is the display list in Flash as it implements a composite pattern. The component nodes in the display list inherit from the &lt;code&gt;DisplayObject&lt;/code&gt; class. The composite nodes inherit from the &lt;code&gt;DisplayObjectContainer&lt;/code&gt; class. The &lt;code&gt;Sprite&lt;/code&gt;, &lt;code&gt;Loader&lt;/code&gt; and &lt;code&gt;Stage&lt;/code&gt; classes extend the &lt;code&gt;DisplayObjectContainer&lt;/code&gt; class as we want them to have child components as in the case of nested sprites. In contrast, the &lt;code&gt;Bitmap&lt;/code&gt;, &lt;code&gt;Shape&lt;/code&gt; and &lt;code&gt;StaticText&lt;/code&gt; classes extend the &lt;code&gt;DisplayObject&lt;/code&gt; class and are true leaf nodes as for example, we don&#039;t want to have nested objects inside a StaticText field.

You are absolutely correct on the second point. I erred on the side of caution as I wasn&#039;t quite sure of how (and when) Flash garbage collection worked. I wish I&#039;d looked at Grant Skinner&#039;s article on mark sweeping which, clearly shows that an isolated collection of objects referencing each other will also get garbage collected.

http://gskinner.com/blog/archives/2006/06/as3_resource_ma.html

I was a little paranoid about leaving a node branch out there with nothing to do.

Glad you like the book. 

-Chandima</description>
		<content:encoded><![CDATA[<p>Hi Ted, quite an interesting question. I think that one would implement a true component to intentionally prevent it from having any children. If you are not quite sure, then all nodes should probably be composites.</p>
<p>A good example is the display list in Flash as it implements a composite pattern. The component nodes in the display list inherit from the <code>DisplayObject</code> class. The composite nodes inherit from the <code>DisplayObjectContainer</code> class. The <code>Sprite</code>, <code>Loader</code> and <code>Stage</code> classes extend the <code>DisplayObjectContainer</code> class as we want them to have child components as in the case of nested sprites. In contrast, the <code>Bitmap</code>, <code>Shape</code> and <code>StaticText</code> classes extend the <code>DisplayObject</code> class and are true leaf nodes as for example, we don&#8217;t want to have nested objects inside a StaticText field.</p>
<p>You are absolutely correct on the second point. I erred on the side of caution as I wasn&#8217;t quite sure of how (and when) Flash garbage collection worked. I wish I&#8217;d looked at Grant Skinner&#8217;s article on mark sweeping which, clearly shows that an isolated collection of objects referencing each other will also get garbage collected.</p>
<p><a href="http://gskinner.com/blog/archives/2006/06/as3_resource_ma.html" rel="nofollow">http://gskinner.com/blog/archives/2006/06/as3_resource_ma.html</a></p>
<p>I was a little paranoid about leaving a node branch out there with nothing to do.</p>
<p>Glad you like the book. </p>
<p>-Chandima</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ted H.</title>
		<link>http://www.as3dp.com/2007/08/05/composite-pattern-extending-the-book-to-add-composite-pages-part-ii/comment-page-1/#comment-565</link>
		<dc:creator>Ted H.</dc:creator>
		<pubDate>Tue, 22 Apr 2008 12:57:33 +0000</pubDate>
		<guid isPermaLink="false">http://www.as3dp.com/2007/08/06/composite-pattern-extending-the-book-to-add-composite-pages-part-ii/#comment-565</guid>
		<description>Hi!  First, TERRIFIC book!  I am new to FLEX and Actionscript (come from a .NET background) and this book has really helped.

I have two questions for you re: the Composite Pattern - one about the pattern itself, one more Actionscript related.

First, I am creating a data structure that&#039;s essentially like a DOM-tree and I don&#039;t know at node-creation-time if the node &quot;is&quot; a branch or a leaf; so I&#039;m making all my nodes branches (composites).  I figured that a leaf is a leaf by simple fact that it has no children, but then I was afraid I&#039;d need to &quot;convert&quot; it to composite if the user decided later they wanted to add child nodes to it.

For example, take a bulleted list (...).  Most of the time the list item will just contain text (and be a leaf), but some of the time, the list item will contain lots of child nodes as well - a table, another list inside a table (which is wrapped in  and  and )...

Is this a common scenario with the Composite Pattern?  I&#039;ve not read anyone else comment on this problem so I assume either I&#039;ve got it wrong, it&#039;s not a common problem, or all my nodes are REALLY Composite nodes (even if they don&#039;t have Children) simply because they CAN have Children.

Any thoughts?

My second question regards removing nodes.  You recursively loop through the child axis to remove nodes to release memory.  I find this confusing. If I simple remove reference to a child node from it&#039;s parent (in the parent&#039;s child nodes array), does this not destroy the children in this axis? 

I mean, do you really need to go through and kill every child node individually to release memory?  If so, can you offer any more detail about this?  I was surprised to hear I needed to do the recursive loop (although maybe I just don&#039;t understand something there too).

Many thanks - again, terrific book (and BLOG!).
-Ted</description>
		<content:encoded><![CDATA[<p>Hi!  First, TERRIFIC book!  I am new to FLEX and Actionscript (come from a .NET background) and this book has really helped.</p>
<p>I have two questions for you re: the Composite Pattern &#8211; one about the pattern itself, one more Actionscript related.</p>
<p>First, I am creating a data structure that&#8217;s essentially like a DOM-tree and I don&#8217;t know at node-creation-time if the node &#8220;is&#8221; a branch or a leaf; so I&#8217;m making all my nodes branches (composites).  I figured that a leaf is a leaf by simple fact that it has no children, but then I was afraid I&#8217;d need to &#8220;convert&#8221; it to composite if the user decided later they wanted to add child nodes to it.</p>
<p>For example, take a bulleted list (&#8230;).  Most of the time the list item will just contain text (and be a leaf), but some of the time, the list item will contain lots of child nodes as well &#8211; a table, another list inside a table (which is wrapped in  and  and )&#8230;</p>
<p>Is this a common scenario with the Composite Pattern?  I&#8217;ve not read anyone else comment on this problem so I assume either I&#8217;ve got it wrong, it&#8217;s not a common problem, or all my nodes are REALLY Composite nodes (even if they don&#8217;t have Children) simply because they CAN have Children.</p>
<p>Any thoughts?</p>
<p>My second question regards removing nodes.  You recursively loop through the child axis to remove nodes to release memory.  I find this confusing. If I simple remove reference to a child node from it&#8217;s parent (in the parent&#8217;s child nodes array), does this not destroy the children in this axis? </p>
<p>I mean, do you really need to go through and kill every child node individually to release memory?  If so, can you offer any more detail about this?  I was surprised to hear I needed to do the recursive loop (although maybe I just don&#8217;t understand something there too).</p>
<p>Many thanks &#8211; again, terrific book (and BLOG!).<br />
-Ted</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: chandima</title>
		<link>http://www.as3dp.com/2007/08/05/composite-pattern-extending-the-book-to-add-composite-pages-part-ii/comment-page-1/#comment-202</link>
		<dc:creator>chandima</dc:creator>
		<pubDate>Thu, 20 Sep 2007 20:56:19 +0000</pubDate>
		<guid isPermaLink="false">http://www.as3dp.com/2007/08/06/composite-pattern-extending-the-book-to-add-composite-pages-part-ii/#comment-202</guid>
		<description>Thanks for the note. If you are interested in how events can cascade down a complex composite structure; For example, when a composite view is incorporated into a model-view-controller pattern, our MVC chapter 12 has some detail on that. The MVC chapter is available as a free download on Adobe DevNet:

http://www.adobe.com/devnet/actionscript/articles/ora_as3_design_patterns.html</description>
		<content:encoded><![CDATA[<p>Thanks for the note. If you are interested in how events can cascade down a complex composite structure; For example, when a composite view is incorporated into a model-view-controller pattern, our MVC chapter 12 has some detail on that. The MVC chapter is available as a free download on Adobe DevNet:</p>
<p><a href="http://www.adobe.com/devnet/actionscript/articles/ora_as3_design_patterns.html" rel="nofollow">http://www.adobe.com/devnet/actionscript/articles/ora_as3_design_patterns.html</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Pdazzle</title>
		<link>http://www.as3dp.com/2007/08/05/composite-pattern-extending-the-book-to-add-composite-pages-part-ii/comment-page-1/#comment-201</link>
		<dc:creator>Pdazzle</dc:creator>
		<pubDate>Thu, 20 Sep 2007 15:07:01 +0000</pubDate>
		<guid isPermaLink="false">http://www.as3dp.com/2007/08/06/composite-pattern-extending-the-book-to-add-composite-pages-part-ii/#comment-201</guid>
		<description>Great book / site. 

How about a part three dealing with handling events in the composite pattern? Would be really helpful.</description>
		<content:encoded><![CDATA[<p>Great book / site. </p>
<p>How about a part three dealing with handling events in the composite pattern? Would be really helpful.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
