ActionScript 3.0 Design Patterns

(Chris Devlin) #1
65

Chapter 2
CHAPTER 2


Factory Method Pattern 2


As experimentation becomes more complex, the need
for the cooperation in it of technical elements from
outside becomes greater and the modern laboratory
tends increasingly to resemble the factory and to
employ in its service increasing numbers of purely
routine workers.
—John Desmond Bernal
The medieval university looked backwards; it
professed to be a storehouse of old knowledge. The
modern university looks forward, and is a factory of
new knowledge.
—Thomas Huxley
One cannot walk through an assembly factory and not
feel that one is in Hell.
—W. H. Auden

What Is the Factory Method Pattern?


One of the most common statements in object-oriented programming (OOP) uses


thenewkeyword to instantiate objects from concrete classes. ActionScript applica-


tions that have multiple classes can have an abundance of code that looks like the


following:


public class Client
{
public function doSomething( )
{
var object:Object = new Product( );
object.manipulate( );
}
}

TheClientclass creates a new instance of theProductclass and assigns it to the


variableobject. There’s nothing wrong with this code, but it does create acoupling

Free download pdf