<?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>Ntt.cc &#187; Design Patterns</title>
	<atom:link href="http://ntt.cc/category/programming/ria-flex/design-patterns/feed" rel="self" type="application/rss+xml" />
	<link>http://ntt.cc</link>
	<description>Flex,Flash,Ajax and Freebie Resource for Developers and Designers</description>
	<lastBuildDate>Tue, 16 Mar 2010 09:26:07 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Download 《Design Patterns in ActionScrip》 Book Free</title>
		<link>http://ntt.cc/2009/04/08/download-design-patterns-in-actionscrip-book-free.html</link>
		<comments>http://ntt.cc/2009/04/08/download-design-patterns-in-actionscrip-book-free.html#comments</comments>
		<pubDate>Wed, 08 Apr 2009 13:35:34 +0000</pubDate>
		<dc:creator>Ntt.cc</dc:creator>
				<category><![CDATA[Design Patterns]]></category>
		<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[GOF]]></category>

		<guid isPermaLink="false">http://ntt.cc/2009/04/08/download-design-patterns-in-actionscrip-book-free.html</guid>
		<description><![CDATA[ If you have ever visited the http://ntt.cc, you may paid attention to the serial of Design Patterns in ActionScript. Since http://ntt.cc based on WordPress system and is Blog style but for many readers is more familiar with the book style. We have spent more time in collecting the serial articles and made a PDF [...]]]></description>
			<content:encoded><![CDATA[<p><img style="border-bottom: 0px; border-left: 0px; border-top: 0px; border-right: 0px" border="0" alt="Shield-Reader-App-128x128" align="left" src="http://ntt.cc/wp-content/uploads/2009/04/shield-reader-app-128x128.png" width="60" height="60"> If you have ever visited the <a href="http://ntt.cc">http://ntt.cc</a>, you may paid attention to the serial of Design Patterns in ActionScript. Since <a href="http://ntt.cc">http://ntt.cc</a> based on WordPress system and is Blog style but for many readers is more familiar with the book style. We have spent more time in collecting the serial articles and made a PDF file for free download.<strong><img alt="Download" src="http://ntt.cc/wp-content/uploads/2008/06/download.png" width="19" height="19"><a href="http://ntt.cc/free-books/Design-Patterns-in-ActionScript/Design%20Patterns%20in%20ActionScript.zip">Download it FREE</a></strong>(or download from here <a href="http://ntt.cc/books">http://ntt.cc/books</a>)</p>
<div style="margin: 0px 15px 15px 15px;">
<script type="text/javascript"><!--
google_ad_client = "pub-2748932162110627";
/* Mac-Ntt.cc-Article-336-280-01 */
google_ad_slot = "9123419006";
google_ad_width = 336;
google_ad_height = 280;
//-->
</script><script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div>
<p><span id="more-1741"></span>
</p>
<div style="width: 447px" class="wp-caption alignleft"><img title="Design Patterns in ActionScript Cover" alt="Design Patterns in ActionScript Cover" src="http://ntt.cc/free-books/Design-Patterns-in-ActionScript/Cover-1.jpg" width="437" height="622">
<p class="wp-caption-text">Design Patterns in ActionScript Cover</p>
</div>
<p><b>The Table of Contents</b>
<p>Preface. 2
<p>Strategy. 4
<p>Factory Method. 8
<p>Abstract Factory. 10
<p>Adapter 13
<p>Decorator 16
<p>Facade. 19
<p>Bridge. 21
<p>Singleton. 24
<p>Observer 26
<p>Template Method. 28
<p>Iterator 30
<p>Prototype. 32
<p>Builder 34
<p>State. 36
<p>Proxy. 39
<p>Interpreter 41
<p>Memento. 44
<p>Visitor 47
<p>Flyweight 51
<p>Composite. 53
<p>Chain of Responsibility. 55
<p>Command. 57
<p>Mediator 59
<p>Final Note. 62</p>
<p><b>About this series</b>
<p>Last summer, when I was busy finding the internship opportunity, I got a message from my classmate. It said that, someone was looking for a writer to write some articles about Flex/Flash. Though I just had little experience on Flex and Flash, I sent a message to the email address given on the message. Then I got this job, and began to write something about FlexUnit.
<p>Minidxer is a very kind person, when he knew that I’m not familiar with the unit test framework, he gave me a new subject, the 23 design patterns from GoF book. In fact, I just knew few simple patterns, but I wanted to learn all the 23 patterns. So, I prepared to write the articles about this.
<p>During the preparing time, I got an internship offer from Ericsson. As you think, I began my intern life at Ericsson, and used my spare time writing the articles. You know, it’s not easy to write something you’re not familiar with. And I don’t have much time after finish my job. Further more, I began my job hunting in September. All those things result that I only finished five patterns in about four months, from August to November.
<p>After finish my internship and job hunting, I began to write the left patterns. Though I spend many times preparing, there are still many mistakes in the articles. I’m just a fresh man in this field <img src='http://ntt.cc/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />
<p>The main reason I wrote these articles is that I want to learn all the 23 patterns. And it would be my honor that these articles can give you some help.
<p><b>Some suggestions</b>
<p>When you begin to learn a new pattern, carefully look at its intent, every pattern has its corresponding problem field.
<p>Then, try to understand the example, understanding how this pattern affects the current design, what problems it solves. If the example is not so clear, use Google to find more examples about this pattern.
<p>In general, you may find many examples write in C++ or Java; try to transform them into ActionScript. It’s a good way for practice. And with these practice, you’ll know the pattern clearly, not only the implementation, but also its nature.
<p>During you learning of patterns, some books are necessary. You should take the &lt;Design Patterns&gt; by GoF on your desk. And other books, such as &lt;Head First Design Patterns&gt;, are also useful for you, which depend on your level, pick up some books that fit you.
<p>Remember, design is a compromise, when it solves some problems, it brings new problems. So, there is no best pattern, but suitable one.
<p>Liu Bo </p>
<h3>Related Post</h3><ul class="related_post"><li><a href="http://ntt.cc/2009/03/10/design-patterns-in-actionscript-final-note.html" title="Design Patterns in ActionScript-Final Note">Design Patterns in ActionScript-Final Note (4)</a></li><li><a href="http://ntt.cc/2009/02/10/gang-of-four-gof-design-patterns-in-actionscript-mediator.html" title="Design Patterns in ActionScript-Mediator">Design Patterns in ActionScript-Mediator (0)</a></li><li><a href="http://ntt.cc/2009/02/09/gang-of-four-gof-design-patterns-in-actionscript-command.html" title="Design Patterns in ActionScript-Command">Design Patterns in ActionScript-Command (1)</a></li><li><a href="http://ntt.cc/2009/02/06/gang-of-four-gof-design-patterns-in-actionscript-chain-of-responsibility.html" title="Design Patterns in ActionScript-Chain of Responsibility">Design Patterns in ActionScript-Chain of Responsibility (0)</a></li><li><a href="http://ntt.cc/2009/02/05/gang-of-four-gof-design-patterns-in-actionscript-flyweight.html" title="Design Patterns in ActionScript-Flyweight">Design Patterns in ActionScript-Flyweight (1)</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://ntt.cc/2009/04/08/download-design-patterns-in-actionscrip-book-free.html/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Design Patterns in ActionScript-Final Note</title>
		<link>http://ntt.cc/2009/03/10/design-patterns-in-actionscript-final-note.html</link>
		<comments>http://ntt.cc/2009/03/10/design-patterns-in-actionscript-final-note.html#comments</comments>
		<pubDate>Tue, 10 Mar 2009 12:56:56 +0000</pubDate>
		<dc:creator>Ntt.cc</dc:creator>
				<category><![CDATA[Design Patterns]]></category>
		<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[GOF]]></category>

		<guid isPermaLink="false">http://ntt.cc/2009/03/10/design-patterns-in-actionscript-final-note.html</guid>
		<description><![CDATA[ In this series, we talk about the 23 design patterns. We use some examples to illustrate how and when to use the patterns, but there is still something I’ve to say here.
Why design patterns?






In my view, design pattern is just a solution to some types of problems, and just a general solution. We use [...]]]></description>
			<content:encoded><![CDATA[</p>
<p><img style="border-bottom: 0px; border-left: 0px; border-top: 0px; border-right: 0px" border="0" alt="dory-256x256" align="left" src="http://ntt.cc/wp-content/uploads/2009/03/dory-256x256.png" width="60" height="60"> In this series, we talk about the 23 design patterns. We use some examples to illustrate how and when to use the patterns, but there is still something I’ve to say here.
<p>Why design patterns?</p>
<div style="margin: 0px 15px 15px 15px;">
<script type="text/javascript"><!--
google_ad_client = "pub-2748932162110627";
/* Mac-Ntt.cc-Article-336-280-01 */
google_ad_slot = "9123419006";
google_ad_width = 336;
google_ad_height = 280;
//-->
</script><script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div>
<p><span id="more-1549"></span>
<p>In my view, design pattern is just a solution to some types of problems, and just a general solution. We use this pattern is just because this pattern is proved to be useful or efficiency to this kind of problem. In general, it’s a better solution, maybe not the best one, but it’s enough in most cases.
<p>With these patterns, you can communicate with your colleagues more easily during the development. You just need to say the pattern name, such as “Singleton”, and your colleagues will understand, “Oh, it’s a singleton, I can’t use the new operator.” You don’t need to explain to your colleagues what the pattern it is.
<p>How and when to use the patterns?
<p>It depends on your experience and what the problem is. Understanding the problem is the first step and the most important step when you build an application.
<p>The following is the conclusion from the GoF book, maybe it helps you.
<p><b>Abstract Factory</b>
<p>Provide an interface for creating families of related or dependent objects without specifying their concrete classes.
<p><a href="http://ntt.cc/2008/10/19/gang-of-four-gof-design-patterns-in-actionscript-abstract-factory.html">http://ntt.cc/2008/10/19/gang-of-four-gof-design-patterns-in-actionscript-abstract-factory.html</a>
<p><b>Builder </b>
<p>Separate the construction of a complex object from its representation so that the same construction process can create different representations. <a name="cat-factory"></a>
<p><a href="http://ntt.cc/2009/01/22/gang-of-four-gof-design-patterns-in-actionscript-builder.html">http://ntt.cc/2009/01/22/gang-of-four-gof-design-patterns-in-actionscript-builder.html</a>
<p><b>Factory Method </b>
<p>Define an interface for creating an object, but let subclasses decide which class to instantiate. Factory Method lets a class defer instantiation to subclasses. <a name="cat-proto"></a>
<p><a href="http://ntt.cc/2008/10/08/gang-of-four-gof-design-patterns-in-actionscript-factory-method.html">http://ntt.cc/2008/10/08/gang-of-four-gof-design-patterns-in-actionscript-factory-method.html</a>
<p><b>Prototype </b>
<p>Specify the kinds of objects to create using a prototypical instance, and create new objects by copying this prototype. <a name="cat-single"></a>
<p><a href="http://ntt.cc/2009/01/21/gang-of-four-gof-design-patterns-in-actionscript-prototype.html">http://ntt.cc/2009/01/21/gang-of-four-gof-design-patterns-in-actionscript-prototype.html</a>
<p><b>Singleton </b>
<p>Ensure a class only has one instance, and provide a global point of access to it.<a name="disc3"></a>
<p><a href="http://ntt.cc/2009/01/12/gang-of-four-gof-design-patterns-in-actionscript-singleton.html">http://ntt.cc/2009/01/12/gang-of-four-gof-design-patterns-in-actionscript-singleton.html</a>
<p><a name="adapter"></a><b>Adapter </b>
<p>Convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn&#8217;t otherwise because of incompatible interfaces.
<p><a href="http://ntt.cc/2008/10/28/gang-of-four-gof-design-patterns-in-actionscript-adapter.html">http://ntt.cc/2008/10/28/gang-of-four-gof-design-patterns-in-actionscript-adapter.html</a>
<p><b>Bridge </b>
<p>Decouple an abstraction from its implementation so that the two can vary independently.
<p><a href="http://ntt.cc/2009/01/11/gang-of-four-gof-design-patterns-in-actionscript-bridge.html">http://ntt.cc/2009/01/11/gang-of-four-gof-design-patterns-in-actionscript-bridge.html</a>
<p><b>Composite </b>
<p>Compose objects into tree structures to represent part-whole hierarchies. Composite lets clients treat individual objects and compositions of objects uniformly. <a name="cat-dec"></a>
<p><a href="http://ntt.cc/2009/01/30/gang-of-four-gof-design-patterns-in-actionscript-composite.html">http://ntt.cc/2009/01/30/gang-of-four-gof-design-patterns-in-actionscript-composite.html</a>
<p><b>Decorator </b>
<p>Attach additional responsibilities to an object dynamically. Decorators provide a flexible alternative to subclassing for extending functionality. <a name="cat-facade"></a>
<p><a href="http://ntt.cc/2008/11/01/gang-of-four-gof-design-patterns-in-actionscript-decorator.html">http://ntt.cc/2008/11/01/gang-of-four-gof-design-patterns-in-actionscript-decorator.html</a>
<p><b>Facade </b>
<p>Provide a unified interface to a set of interfaces in a subsystem. Facade defines a higher-level interface that makes the subsystem easier to use. <a name="cat-flywt"></a>
<p><a href="http://ntt.cc/2009/01/10/gang-of-four-gof-design-patterns-in-actionscript-facade.html">http://ntt.cc/2009/01/10/gang-of-four-gof-design-patterns-in-actionscript-facade.html</a>
<p><b>Flyweight </b>
<p>Use sharing to support large numbers of fine-grained objects efficiently. <a name="cat-proxy"></a>
<p><a href="http://ntt.cc/2009/02/05/gang-of-four-gof-design-patterns-in-actionscript-flyweight.html">http://ntt.cc/2009/02/05/gang-of-four-gof-design-patterns-in-actionscript-flyweight.html</a>
<p><b>Proxy </b>
<p>Provide a surrogate or placeholder for another object to control access to it.<a name="disc4"></a><a name="behavioral"></a>
<p><a href="http://ntt.cc/2009/01/25/gang-of-four-gof-design-patterns-in-actionscript-proxy.html">http://ntt.cc/2009/01/25/gang-of-four-gof-design-patterns-in-actionscript-proxy.html</a>
<p><b>Chain of Responsibility </b>
<p>Avoid coupling the sender of a request to its receiver by giving more than one object a chance to handle the request. Chain the receiving objects and pass the request along the chain until an object handles it.
<p><a href="http://ntt.cc/2009/02/06/gang-of-four-gof-design-patterns-in-actionscript-chain-of-responsibility.html">http://ntt.cc/2009/02/06/gang-of-four-gof-design-patterns-in-actionscript-chain-of-responsibility.html</a>
<p><b>Command </b>
<p>Encapsulate a request as an object, thereby letting you parameterize clients with different requests, queue or log requests, and support undoable operations.
<p><a href="http://ntt.cc/2009/02/09/gang-of-four-gof-design-patterns-in-actionscript-command.html">http://ntt.cc/2009/02/09/gang-of-four-gof-design-patterns-in-actionscript-command.html</a>
<p><b>Interpreter </b>
<p>Given a language, define a represention for its grammar along with an interpreter that uses the representation to interpret sentences in the language.
<p><a href="http://ntt.cc/2009/01/27/gang-of-four-gof-design-patterns-in-actionscript-interpreter.html">http://ntt.cc/2009/01/27/gang-of-four-gof-design-patterns-in-actionscript-interpreter.html</a>
<p><b>Iterator</b>
<p>Provide a way to access the elements of an aggregate object sequentially without exposing its underlying representation. <a name="cat-media"></a>
<p><a href="http://ntt.cc/2009/01/18/gang-of-four-gof-design-patterns-in-actionscript-iterator.html">http://ntt.cc/2009/01/18/gang-of-four-gof-design-patterns-in-actionscript-iterator.html</a>
<p><b>Mediator</b>
<p>Define an object that encapsulates how a set of objects interact. Mediator promotes loose coupling by keeping objects from referring to each other explicitly, and it lets you vary their interaction independently. <a name="cat-memen"></a>
<p><a href="http://ntt.cc/2009/02/10/gang-of-four-gof-design-patterns-in-actionscript-mediator.html">http://ntt.cc/2009/02/10/gang-of-four-gof-design-patterns-in-actionscript-mediator.html</a>
<p><b>Memento </b>
<p>Without violating encapsulation, capture and externalize an object&#8217;s internal state so that the object can be restored to this state later.
<p><a href="http://ntt.cc/2009/02/01/gang-of-four-gof-design-patterns-in-actionscript-memento.html">http://ntt.cc/2009/02/01/gang-of-four-gof-design-patterns-in-actionscript-memento.html</a>
<p><b></b>
<p><b>Observer </b>
<p>Define a one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically. <a name="cat-state"></a>
<p><a href="http://ntt.cc/2009/01/13/gang-of-four-gof-design-patterns-in-actionscript-observer.html">http://ntt.cc/2009/01/13/gang-of-four-gof-design-patterns-in-actionscript-observer.html</a>
<p><b>State </b>
<p>Allow an object to alter its behavior when its internal state changes. The object will appear to change its class. <a name="cat-strat"></a>
<p><a href="http://ntt.cc/2009/01/25/gang-of-four-gof-design-patterns-in-actionscript-state.html">http://ntt.cc/2009/01/25/gang-of-four-gof-design-patterns-in-actionscript-state.html</a>
<p><b>Strategy </b>
<p>Define a family of algorithms, encapsulate each one, and make them interchangeable. Strategy lets the algorithm vary independently from clients that use it. <a name="cat-tempmeth"></a>
<p><a href="http://ntt.cc/2008/10/07/gang-of-four-gof-design-patterns-in-actionscript-strategy.html">http://ntt.cc/2008/10/07/gang-of-four-gof-design-patterns-in-actionscript-strategy.html</a>
<p><b>Template Method </b>
<p>Define the skeleton of an algorithm in an operation, deferring some steps to subclasses. Template Method lets subclasses redefine certain steps of an algorithm without changing the algorithm&#8217;s structure. <a name="cat-visit"></a>
<p><a href="http://ntt.cc/2009/01/16/gang-of-four-gof-design-patterns-in-actionscript-template-method.html">http://ntt.cc/2009/01/16/gang-of-four-gof-design-patterns-in-actionscript-template-method.html</a>
<p><b>Visitor </b>
<p>Represent an operation to be performed on the elements of an object structure. Visitor lets you define a new operation without changing the classes of the elements on which it operates.
<p><a href="http://ntt.cc/2009/02/03/gang-of-four-gof-design-patterns-in-actionscript-visitor.html">http://ntt.cc/2009/02/03/gang-of-four-gof-design-patterns-in-actionscript-visitor.html</a></p>
<h3>Related Post</h3><ul class="related_post"><li><a href="http://ntt.cc/2009/04/08/download-design-patterns-in-actionscrip-book-free.html" title="Download 《Design Patterns in ActionScrip》 Book Free">Download 《Design Patterns in ActionScrip》 Book Free (7)</a></li><li><a href="http://ntt.cc/2009/02/10/gang-of-four-gof-design-patterns-in-actionscript-mediator.html" title="Design Patterns in ActionScript-Mediator">Design Patterns in ActionScript-Mediator (0)</a></li><li><a href="http://ntt.cc/2009/02/09/gang-of-four-gof-design-patterns-in-actionscript-command.html" title="Design Patterns in ActionScript-Command">Design Patterns in ActionScript-Command (1)</a></li><li><a href="http://ntt.cc/2009/02/06/gang-of-four-gof-design-patterns-in-actionscript-chain-of-responsibility.html" title="Design Patterns in ActionScript-Chain of Responsibility">Design Patterns in ActionScript-Chain of Responsibility (0)</a></li><li><a href="http://ntt.cc/2009/02/05/gang-of-four-gof-design-patterns-in-actionscript-flyweight.html" title="Design Patterns in ActionScript-Flyweight">Design Patterns in ActionScript-Flyweight (1)</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://ntt.cc/2009/03/10/design-patterns-in-actionscript-final-note.html/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Design Patterns in ActionScript-Mediator</title>
		<link>http://ntt.cc/2009/02/10/gang-of-four-gof-design-patterns-in-actionscript-mediator.html</link>
		<comments>http://ntt.cc/2009/02/10/gang-of-four-gof-design-patterns-in-actionscript-mediator.html#comments</comments>
		<pubDate>Tue, 10 Feb 2009 12:13:45 +0000</pubDate>
		<dc:creator>Ntt.cc</dc:creator>
				<category><![CDATA[Design Patterns]]></category>
		<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Design Pattern]]></category>
		<category><![CDATA[GOF]]></category>
		<category><![CDATA[Mediator]]></category>

		<guid isPermaLink="false">http://ntt.cc/2009/02/10/gang-of-four-gof-design-patterns-in-actionscript-mediator.html</guid>
		<description><![CDATA[ Ok, the last pattern now. Let’s take a look the intent directly.
Define an object that encapsulates how a set of objects interact. Mediator promotes loose coupling by keeping objects from referring to each other explicitly, and it lets you vary their interaction independently.
&#8211; By THE GOF BOOK
From this intent, we can get that this [...]]]></description>
			<content:encoded><![CDATA[<p><img style="border-bottom: 0px; border-left: 0px; border-top: 0px; border-right: 0px" border="0" alt="My-Documents-256x256" align="left" src="http://ntt.cc/wp-content/uploads/2009/02/my-documents-256x256.png" width="60" height="60"> Ok, the last pattern now. Let’s take a look the intent directly.
<p><b>Define an object that encapsulates how a set of objects interact. Mediator promotes loose coupling by keeping objects from referring to each other explicitly, and it lets you vary their interaction independently.</b>
<p><b>&#8211; By THE GOF BOOK</b>
<p>From this intent, we can get that this pattern is use for encapsulating the interaction of objects. </p>
<div style="margin: 0px 15px 15px 15px;">
<script type="text/javascript"><!--
google_ad_client = "pub-2748932162110627";
/* Mac-Ntt.cc-Article-336-280-01 */
google_ad_slot = "9123419006";
google_ad_width = 336;
google_ad_height = 280;
//-->
</script><script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div>
<p><span id="more-1399"></span> </p>
<p>
<p>For example, when you build a GUI application, you may enable or disable the button when the user input something, you may add a listener for the text change event. Then, when the event happens, you change the state of that button. It means that you must know the button object, and some details about the button. As you application going further, you may do many things in that function, also, you need to know many classes’ detail. When the requirement changed, you need to fix many things. And your classes maybe look like as follows.
<p><a href="http://ntt.cc/wp-content/uploads/2009/02/clip-image0011.jpg"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="clip_image001" src="http://ntt.cc/wp-content/uploads/2009/02/clip-image001-thumb1.jpg" width="262" height="170"></a>
<p>With the help of Mediator pattern, you reduce the complexity of each widget, they don’t even need to know the existence of other widgets, and they only need to know the mediator. When an object changes, it tells the mediator, then the mediator notify the other objects. In this pattern, you put the complexity from the widget to the mediator. The mediator needs to know everything. And the classes changes to below.
<p><a href="http://ntt.cc/wp-content/uploads/2009/02/clip-image0021.jpg"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="clip_image002" src="http://ntt.cc/wp-content/uploads/2009/02/clip-image002-thumb1.jpg" width="340" height="241"></a>
<p>In GoF, all the widgets will inherit a super class Colleague, and the widgets is called concrete colleague. When the widget’s state changes, it calls the widgetChanged() method. My simple implementation of colleague is as follows.  </p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline"><span style="color: Green;">public</span><span style="color: Gray;"> </span><span style="color: Green;">class</span><span style="color: Gray;"> </span><span style="color: Blue;">Colleague</span></li>
<li><span style="color: Olive;">{</span></li>
<li><span style="color: Green;">private</span><span style="color: Gray;">&nbsp;</span><span style="color: Green;">var</span><span style="color: Gray;"> </span><span style="color: Blue;">mediator</span><span style="color: Gray;">:</span><span style="color: Blue;">Mediator</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp;</span></li>
<li><span style="color: Green;">public</span><span style="color: Gray;">&nbsp;</span><span style="color: Green;">function</span><span style="color: Gray;"> </span><span style="color: Blue;">Colleague</span><span style="color: Olive;">(</span><span style="color: Blue;">mediator</span><span style="color: Gray;">:</span><span style="color: Blue;">Mediator</span><span style="color: Olive;">)</span></li>
<li><span style="color: Olive;">{</span></li>
<li><span style="color: Green;">this</span><span style="color: Gray;">.</span><span style="color: Blue;">mediator</span><span style="color: Gray;"> = </span><span style="color: Blue;">mediator</span><span style="color: Gray;">;</span></li>
<li><span style="color: Olive;">}</span></li>
<li><span style="color: Gray;">&nbsp;</span></li>
<li><span style="color: Green;">public</span><span style="color: Gray;">&nbsp;</span><span style="color: Green;">function</span><span style="color: Gray;"> </span><span style="color: Blue;">hasChanged</span><span style="color: Olive;">()</span><span style="color: Gray;">:</span><span style="color: Teal;">String</span></li>
<li><span style="color: Olive;">{</span></li>
<li><span style="color: Green;">return</span><span style="color: Gray;">&nbsp;</span><span style="color: Blue;">mediator</span><span style="color: Gray;">.</span><span style="color: Blue;">detectChanged</span><span style="color: Olive;">(</span><span style="color: Green;">this</span><span style="color: Olive;">)</span><span style="color: Gray;">;</span></li>
<li><span style="color: Olive;">}</span></li>
<li><span style="color: Olive;">}</span></li></ol></div>
<p>In the concrete mediator, we need to distinguish which objects call the method, and here is my implementation.  </p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline"><span style="color: Green;">public</span><span style="color: Gray;"> </span><span style="color: Green;">function</span><span style="color: Gray;"> </span><span style="color: Blue;">detectChanged</span><span style="color: Olive;">(</span><span style="color: Blue;">colleague</span><span style="color: Gray;">:</span><span style="color: Blue;">Colleague</span><span style="color: Olive;">)</span><span style="color: Gray;">:</span><span style="color: Teal;">String</span></li>
<li><span style="color: Olive;">{</span></li>
<li><span style="color: Green;">if</span><span style="color: Olive;">(</span><span style="color: Blue;">colleague</span><span style="color: Gray;"> == </span><span style="color: Blue;">colleague1</span><span style="color: Olive;">)</span></li>
<li><span style="color: Green;">return</span><span style="color: Gray;">&nbsp;</span><span style="color: Blue;">colleague2</span><span style="color: Gray;">.</span><span style="color: Blue;">operation2</span><span style="color: Olive;">()</span><span style="color: Gray;">;</span></li>
<li><span style="color: Green;">else</span><span style="color: Gray;">&nbsp;</span><span style="color: Green;">if</span><span style="color: Olive;">(</span><span style="color: Blue;">colleague</span><span style="color: Gray;"> == </span><span style="color: Blue;">colleague2</span><span style="color: Olive;">)</span></li>
<li><span style="color: Green;">return</span><span style="color: Gray;">&nbsp;</span><span style="color: Blue;">colleague1</span><span style="color: Gray;">.</span><span style="color: Blue;">operation1</span><span style="color: Olive;">()</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp;</span></li>
<li><span style="color: Green;">return</span><span style="color: Gray;">&nbsp;</span><span style="color: Green;">null</span><span style="color: Gray;">;</span></li>
<li><span style="color: Olive;">}</span></li></ol></div>
<p>And the class diagram below is from the GoF.
<p><a href="http://ntt.cc/wp-content/uploads/2009/02/clip-image003.gif"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="clip_image003" src="http://ntt.cc/wp-content/uploads/2009/02/clip-image003-thumb.gif" width="484" height="153"></a>
<p>Hope this helps. That’s all for this pattern.<img alt="Download" src="http://ntt.cc/wp-content/uploads/2008/06/download.png" width="19" height="19"> <a href="http://ntt.cc/ext/gang-of-four-gof-design-patterns-in-actionscript-Mediator/Mediator.zip" target="_blank">Download Full Project</a>
<p>Thanks for you kindness in reading those articles, especially for those who make comments. Actually, I’m a fresh man in design patterns; the main reason that I wrote those articles is to help me learn more quickly. If there is any wrong that troubles you, I’ve to say sorry here, sincerely! If you have any questions, contact me, <a href="mailto:liubo.cs@hotmail.com">liubo.cs@hotmail.com</a>.</p>
<h3>Related Post</h3><ul class="related_post"><li><a href="http://ntt.cc/2009/02/09/gang-of-four-gof-design-patterns-in-actionscript-command.html" title="Design Patterns in ActionScript-Command">Design Patterns in ActionScript-Command (1)</a></li><li><a href="http://ntt.cc/2009/02/06/gang-of-four-gof-design-patterns-in-actionscript-chain-of-responsibility.html" title="Design Patterns in ActionScript-Chain of Responsibility">Design Patterns in ActionScript-Chain of Responsibility (0)</a></li><li><a href="http://ntt.cc/2009/02/05/gang-of-four-gof-design-patterns-in-actionscript-flyweight.html" title="Design Patterns in ActionScript-Flyweight">Design Patterns in ActionScript-Flyweight (1)</a></li><li><a href="http://ntt.cc/2009/02/03/gang-of-four-gof-design-patterns-in-actionscript-visitor.html" title="Design Patterns in ActionScript-Visitor">Design Patterns in ActionScript-Visitor (3)</a></li><li><a href="http://ntt.cc/2009/02/01/gang-of-four-gof-design-patterns-in-actionscript-memento.html" title="Design Patterns in ActionScript-Memento">Design Patterns in ActionScript-Memento (1)</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://ntt.cc/2009/02/10/gang-of-four-gof-design-patterns-in-actionscript-mediator.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Design Patterns in ActionScript-Command</title>
		<link>http://ntt.cc/2009/02/09/gang-of-four-gof-design-patterns-in-actionscript-command.html</link>
		<comments>http://ntt.cc/2009/02/09/gang-of-four-gof-design-patterns-in-actionscript-command.html#comments</comments>
		<pubDate>Mon, 09 Feb 2009 14:43:40 +0000</pubDate>
		<dc:creator>Ntt.cc</dc:creator>
				<category><![CDATA[Design Patterns]]></category>
		<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Command]]></category>
		<category><![CDATA[Design Pattern]]></category>
		<category><![CDATA[GOF]]></category>

		<guid isPermaLink="false">http://ntt.cc/2009/02/09/gang-of-four-gof-design-patterns-in-actionscript-command.html</guid>
		<description><![CDATA[ A few months ago, I was an intern of a company. I joined a group which builds a LBS application, and our target platform including J2ME and Android. I was asked to make a J2ME demo.
This demo was just like the Google map on J2ME. Eh, actually, we did something more than that; but [...]]]></description>
			<content:encoded><![CDATA[<p><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="insurance-256x256" align="left" src="http://ntt.cc/wp-content/uploads/2009/02/insurance-256x256.png" width="60" height="60"> A few months ago, I was an intern of a company. I joined a group which builds a LBS application, and our target platform including J2ME and Android. I was asked to make a J2ME demo.
<p>This demo was just like the Google map on J2ME. Eh, actually, we did something more than that; but you don’t need to know, just considering we’re going to build a Google map on J2ME platform.  </p>
<div style="margin: 0px 15px 15px 15px;">
<script type="text/javascript"><!--
google_ad_client = "pub-2748932162110627";
/* Mac-Ntt.cc-Article-336-280-01 */
google_ad_slot = "9123419006";
google_ad_width = 336;
google_ad_height = 280;
//-->
</script><script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div>
<p><span id="more-1389"></span> </p>
<p>As our project going, we can fetched the map tile and display it on the screen. When the user pressed the direction key, we created a new connection to fetch the map tile, and then display it on the screen. The code is maybe as follows. I hope you can understand the following code <img src='http://ntt.cc/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline"><span style="color: Blue;">Var</span><span style="color: Gray;"> </span><span style="color: Blue;">directionBtn</span><span style="color: Gray;">:</span><span style="color: Teal;">Button</span><span style="color: Gray;"> = </span><span style="color: Green;">new</span><span style="color: Gray;"> </span><span style="color: Teal;">Button</span><span style="color: Olive;">()</span><span style="color: Gray;">;</span></li>
<li><span style="color: Blue;">directionBtn</span><span style="color: Gray;">.</span><span style="color: Blue;">addMouseEventListener</span><span style="color: Olive;">(</span><span style="color: Teal;">Mouse</span><span style="color: Gray;">.</span><span style="color: Blue;">Click</span><span style="color: Gray;">, “</span><span style="color: Blue;">downloadTile</span><span style="color: Gray;">”</span><span style="color: Olive;">)</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp;</span></li>
<li><span style="color: Green;">function</span><span style="color: Gray;">&nbsp;</span><span style="color: Blue;">downloadTile</span><span style="color: Olive;">()</span><span style="color: Gray;">:</span><span style="color: Green;">void</span></li>
<li><span style="color: Olive;">{</span></li>
<li><span style="color: Blue;">Var</span><span style="color: Gray;">&nbsp;</span><span style="color: Blue;">conn</span><span style="color: Gray;">:</span><span style="color: Blue;">Connection</span><span style="color: Gray;"> = </span><span style="color: Blue;">ConnectionFactory</span><span style="color: Gray;">.</span><span style="color: Blue;">getConnection</span><span style="color: Olive;">()</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp;</span></li>
<li><span style="color: Blue;">DrawOnScreen</span><span style="color: Olive;">(</span><span style="color: Blue;">conn</span><span style="color: Olive;">)</span><span style="color: Gray;">;</span></li>
<li><span style="color: Olive;">}</span></li></ol></div>
<p>Note: the above code is pseudo code. Don’t try to complier it.
<p>If you ever use some similar application on your phone, you may realize where the problem is. Let me figure it out. When the user wants to drag the map, the application will seems to be as no response. It means, when the user holds a direction, the application will produce many connections, and only 5 connections can be executed at the same time, and each connection may be finished in 3 or 5 seconds. (Note: 5 connections at one time are depending on our test, and each connection’s time spending is depends on the network.)
<p>So, our problem is that, when the user drags the map, the application will download all the tiles. Actually, not all the tiles are needed, the tiles the user wants is where the user drags to not the way it passes.
<p>Wow, genius, maybe you have your own solution now. And our solution is use a stack to hold the commands. That is, when the user presses a direction key, it puts a common into the stack, and we execute the commands from the top one. So, the most recent request will execute first. And now, our code will be as below.  </p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline"><span style="color: Blue;">directionBtn</span><span style="color: Gray;">.</span><span style="color: Blue;">addMouseEventListener</span><span style="color: Olive;">(</span><span style="color: Teal;">Mouse</span><span style="color: Gray;">.</span><span style="color: Blue;">Click</span><span style="color: Gray;">, “</span><span style="color: Blue;">downloadTile</span><span style="color: Gray;">”</span><span style="color: Olive;">)</span><span style="color: Gray;">;</span></li>
<li><span style="color: Green;">function</span><span style="color: Gray;">&nbsp;</span><span style="color: Blue;">downloadTile</span><span style="color: Olive;">()</span><span style="color: Gray;">:</span><span style="color: Green;">void</span></li>
<li><span style="color: Olive;">{</span></li>
<li><span style="color: Blue;">requestStack</span><span style="color: Gray;">.</span><span style="color: Teal;">push</span><span style="color: Olive;">(</span><span style="color: Green;">new</span><span style="color: Gray;">&nbsp;</span><span style="color: Blue;">Request</span><span style="color: Olive;">())</span><span style="color: Gray;">;</span></li>
<li><span style="color: Olive;">}</span></li></ol></div>
<p>The most difference between the two is that we put a method into an object. And this is the Command pattern.
<p>See the intent now <img src='http://ntt.cc/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />
<p><b>Encapsulate a request as an object, thereby letting you parameterize clients with different requests, queue or log requests, and support undoable operations.</b>
<p><b>&#8211; By THE GOF BOOK</b>
<p>With this pattern, you can make a request queue, or implement a logger system or the UNDO / REDO command.
<p>If you want, you can take a look at the example code <img src='http://ntt.cc/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  <img alt="Download" src="http://ntt.cc/wp-content/uploads/2008/06/download.png" width="19" height="19"> <a href="http://ntt.cc/ext/gang-of-four-gof-design-patterns-in-actionscript-Command/Command.zip" target="_blank">Download Full Project</a>
<p>Enjoy!</p>
<h3>Related Post</h3><ul class="related_post"><li><a href="http://ntt.cc/2009/02/10/gang-of-four-gof-design-patterns-in-actionscript-mediator.html" title="Design Patterns in ActionScript-Mediator">Design Patterns in ActionScript-Mediator (0)</a></li><li><a href="http://ntt.cc/2009/02/06/gang-of-four-gof-design-patterns-in-actionscript-chain-of-responsibility.html" title="Design Patterns in ActionScript-Chain of Responsibility">Design Patterns in ActionScript-Chain of Responsibility (0)</a></li><li><a href="http://ntt.cc/2009/02/05/gang-of-four-gof-design-patterns-in-actionscript-flyweight.html" title="Design Patterns in ActionScript-Flyweight">Design Patterns in ActionScript-Flyweight (1)</a></li><li><a href="http://ntt.cc/2009/02/03/gang-of-four-gof-design-patterns-in-actionscript-visitor.html" title="Design Patterns in ActionScript-Visitor">Design Patterns in ActionScript-Visitor (3)</a></li><li><a href="http://ntt.cc/2009/02/01/gang-of-four-gof-design-patterns-in-actionscript-memento.html" title="Design Patterns in ActionScript-Memento">Design Patterns in ActionScript-Memento (1)</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://ntt.cc/2009/02/09/gang-of-four-gof-design-patterns-in-actionscript-command.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Design Patterns in ActionScript-Chain of Responsibility</title>
		<link>http://ntt.cc/2009/02/06/gang-of-four-gof-design-patterns-in-actionscript-chain-of-responsibility.html</link>
		<comments>http://ntt.cc/2009/02/06/gang-of-four-gof-design-patterns-in-actionscript-chain-of-responsibility.html#comments</comments>
		<pubDate>Fri, 06 Feb 2009 12:58:11 +0000</pubDate>
		<dc:creator>Ntt.cc</dc:creator>
				<category><![CDATA[Design Patterns]]></category>
		<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Chain of Responsibility]]></category>
		<category><![CDATA[Design Pattern]]></category>
		<category><![CDATA[GOF]]></category>

		<guid isPermaLink="false">http://ntt.cc/2009/02/06/gang-of-four-gof-design-patterns-in-actionscript-chain-of-responsibility.html</guid>
		<description><![CDATA[ When you need some help in a hotel, you may ask the attendant firstly, if the attend can’t help you, then the attendant may pass you question to the assistant manager, if the attendant still can’t help you, then the question maybe pass to the lobby manager.







The picture above shows the way your question [...]]]></description>
			<content:encoded><![CDATA[<p><img style="border-bottom: 0px; border-left: 0px; border-top: 0px; border-right: 0px" border="0" alt="FTP-Client-128x128" align="left" src="http://ntt.cc/wp-content/uploads/2009/02/ftp-client-128x128.png" width="60" height="60"> When you need some help in a hotel, you may ask the attendant firstly, if the attend can’t help you, then the attendant may pass you question to the assistant manager, if the attendant still can’t help you, then the question maybe pass to the lobby manager.</p>
<div style="margin: 0px 15px 15px 15px;">
<script type="text/javascript"><!--
google_ad_client = "pub-2748932162110627";
/* Mac-Ntt.cc-Article-336-280-01 */
google_ad_slot = "9123419006";
google_ad_width = 336;
google_ad_height = 280;
//-->
</script><script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div>
<p><span id="more-1384"></span>
<p><a href="http://ntt.cc/wp-content/uploads/2009/02/question.png"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="Question" src="http://ntt.cc/wp-content/uploads/2009/02/question-thumb.png" width="480" height="162"></a>
<p>The picture above shows the way your question passes through. In fact, you don’t need to care the path your question pass through; you just need to know, some one in the chain will give you an answer. And it has a corresponding pattern called Chain of Responsibility.
<p>The intent of this pattern is as below.
<p><b>Avoid coupling the sender of a request to its receiver by giving more than one object a chance to handle the request. Chain the receiving objects and pass the request along the chain until an object handles it.</b>
<p><b>&#8211; By THE GOF BOOK</b>
<p>In the scene above, we may need three classes to handle the help message; further more, we need a common interface for these classes.
<p>The class diagram will be as follows.
<p><a href="http://ntt.cc/wp-content/uploads/2009/02/clip-image0031.jpg"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="clip_image003" src="http://ntt.cc/wp-content/uploads/2009/02/clip-image003-thumb1.jpg" width="484" height="267"></a>
<p>And if you want to use these classes, you need to specify each successor just as below.  </p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline"><span style="color: Blue;">attendant</span><span style="color: Gray;"> = </span><span style="color: Green;">new</span><span style="color: Gray;"> </span><span style="color: Blue;">Attendant</span><span style="color: Olive;">()</span><span style="color: Gray;">;</span></li>
<li><span style="color: Blue;">assistantManager</span><span style="color: Gray;"> = </span><span style="color: Green;">new</span><span style="color: Gray;">&nbsp;</span><span style="color: Blue;">AssistantManager</span><span style="color: Olive;">()</span><span style="color: Gray;">;</span></li>
<li><span style="color: Blue;">lobbyManager</span><span style="color: Gray;"> = </span><span style="color: Green;">new</span><span style="color: Gray;">&nbsp;</span><span style="color: Blue;">LobbyManager</span><span style="color: Olive;">()</span><span style="color: Gray;">;</span></li>
<li><span style="color: Blue;">attendant</span><span style="color: Gray;">.</span><span style="color: Blue;">setSuccessor</span><span style="color: Olive;">(</span><span style="color: Blue;">assistantManager</span><span style="color: Olive;">)</span><span style="color: Gray;">;</span></li>
<li><span style="color: Blue;">assistantManager</span><span style="color: Gray;">.</span><span style="color: Blue;">setSuccessor</span><span style="color: Olive;">(</span><span style="color: Blue;">lobbyManager</span><span style="color: Olive;">)</span><span style="color: Gray;">;</span></li></ol></div>
<p>When a client ask a question, you can simply call the attendant.helpMsg(), and in the helpMsg() method of each concrete helper, it can decide help or not depends on it’s own state. Eh, here I simply use the random number to decide pass the request or handle it. If you want to change the sequence, just change the successor by calling the setSuccessor() method.
<p>The above introduction is a use of this pattern; someone said that it’s pure CoR (Chain of Responsibility). There is another use of this pattern, eh, it’s not pure CoR. In the not pure way, all the classes in the chain will work together to finish a job. Such as the pipeline, you can let each class take one step, then pass the request from the first one till the last one, then all the steps will finish, so the job is done. That’s all for this pattern.<img alt="Download" src="http://ntt.cc/wp-content/uploads/2008/06/download.png" width="19" height="19"> <a href="http://ntt.cc/ext/gang-of-four-gof-design-patterns-in-actionscript-Chain-of-Responsibility/Chain-Of-Responsibility.zip" target="_blank">Download Full Project</a>
<p>Enjoy!</p>
<h3>Related Post</h3><ul class="related_post"><li><a href="http://ntt.cc/2009/02/10/gang-of-four-gof-design-patterns-in-actionscript-mediator.html" title="Design Patterns in ActionScript-Mediator">Design Patterns in ActionScript-Mediator (0)</a></li><li><a href="http://ntt.cc/2009/02/09/gang-of-four-gof-design-patterns-in-actionscript-command.html" title="Design Patterns in ActionScript-Command">Design Patterns in ActionScript-Command (1)</a></li><li><a href="http://ntt.cc/2009/02/05/gang-of-four-gof-design-patterns-in-actionscript-flyweight.html" title="Design Patterns in ActionScript-Flyweight">Design Patterns in ActionScript-Flyweight (1)</a></li><li><a href="http://ntt.cc/2009/02/03/gang-of-four-gof-design-patterns-in-actionscript-visitor.html" title="Design Patterns in ActionScript-Visitor">Design Patterns in ActionScript-Visitor (3)</a></li><li><a href="http://ntt.cc/2009/02/01/gang-of-four-gof-design-patterns-in-actionscript-memento.html" title="Design Patterns in ActionScript-Memento">Design Patterns in ActionScript-Memento (1)</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://ntt.cc/2009/02/06/gang-of-four-gof-design-patterns-in-actionscript-chain-of-responsibility.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
