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 file for free download.Download it FREE(or download from here http://ntt.cc/books)
Archive for the ‘Design Patterns’ Category
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?
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.
– By THE GOF BOOK
From this intent, we can get that this pattern is use for encapsulating the interaction of objects.
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 you don’t need to know, just considering we’re going to build a Google map on J2ME platform.
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.
In Action Script 3.0 we have the following ways to define a String.
var str1:String = new String(”foo”); var str2:String = “foo”; var str3:String = String(”foo”);
I don’t know which way is your way, but they work the same way. Actually, all of the three String variables point to the same String object in memory. That’s to say there is only one copy of “foo” object in the memory, but three references. In other languages, such as java, are almost the same. It saves the memory. This is called object pool. And there is a similar pattern called Flyweight.
Let’s take a look at its intent.
It’s our winter holiday now, and I spend many times in playing games. In last week, I soaked myself in <Prince of Persia: the sands of time>. I love this game, but it’s a pity for me that when I fight to the monsters, I can’t control the heroine. Because of that sometimes I need her help to shot somebody exactly not the other one. OK, I’m crazy Controlling two roles will increase the difficulty of manipulation, and it’s not a RTS game.
Now, I’m using Microsoft word to write these articles. These word processor programs are very useful when you writing something down. Sometimes, we heard someone was very familiar with these programs, such as word, can remember many short-cuts. Though I use this program frequently, I can’t remember many short-cuts. I can remember some short-cuts, such as “Ctrl+Z”, which means UNDO.