Posts Tagged ‘Flyweight’

Design Patterns in ActionScript-Flyweight

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.

(more…)