Search This Blog

Monday, February 06, 2006

Creational Patterns

All of the creational patterns deal with the best way to create
instances of objects. This is important because your program should not
depend on how objects are created and arranged. In Java, of course, the
simplest way to create an instance of an object is by using the new operator.
Fred = new Fred();

//instance of Fred class
However, this really amounts to hard coding, depending on how you
create the object within your program. In many cases, the exact nature of the
object that is created could vary with the needs of the program and
abstracting the creation process into a special “creator” class can make your
program more flexible and general.

The Factory Method provides a simple decision making class that
returns one of several possible subclasses of an abstract base class depending
on the data that are provided.

The Abstract Factory Method provides an interface to create and
return one of several families of related objects.

The Builder Pattern separates the construction of a complex object
from its representation, so that several different representations can be created
depending on the needs of the program.

The Prototype Pattern starts with an initialized and instantiated
class and copies or clones it to make new instances rather than creating new

The Singleton Pattern is a class of which there can be no more than
one instance. It provides a single global point of access to that instance.

No comments: