ActionScript 3.0 Design Patterns

(Chris Devlin) #1

PART II


II.Creational Patterns


If the Lord Almighty had consulted me before
embarking on creation thus, I should have
recommended something simpler.
—Attributed to Alfonso the Wise (13th century Castilian
king and wise guy)
To exist is to change, to change is to mature, to
mature is to go on creating oneself endlessly.
—Henri Bergson
There is nothing like a dream to create the future.
—Victor Hugo

This first section examines design patterns that abstract the instantiation process.


The creator pattern separates the use of objects from their creation. The separation


process is accomplished by encapsulation. The concrete class uses the encapsulated


information, but has no direct knowledge of that information. At the same time, the


concrete class masks how the instances themselves are created and constructed.


Figure Part II-1 shows a general figure of the two main features of creational


patterns.


The two design patterns we examine as representatives of the creational patterns are


very different. The Factory Method pattern solves the problem of the tight coupling


between theClientand theProductby delegating the object creation to a separate


method called afactory; hence the name Factory Method. The Singleton method is


charged with making sure that asingleinstance and only a single instance of a class is


created, and so derives its name from the single instance it instantiates. The Single-


ton design pattern is often used in conjunction with other design patterns as a gate-


way when the developer needs to make sure that only one instance of some aspect of


the pattern is instantiated.


Chapter 2,Factory Method Pattern
Chapter 3,Singleton Pattern
Free download pdf