Tuesday, July 17, 2007

Design Patterns: Creational Patterns

Creational patterns deal with the best way to create instances of objects.

Abstract Factory Pattern

  • This pattern is one level of abstraction higher than the factory pattern. It is a factory object that returns one of several factories.

Builder Pattern

  • This pattern assembles a number of objects, in various ways depending on the data.
  • This is a little more than just a Factory pattern, because we aren’t returning objects which are simple descendents of a base display object, but totally different user interfaces made up of different combinations of display objects.
  • A typical example is your E-mail address book. You probably have both people and groups of people in your address book, and you would expect the display for the address book to change so that the People screen has places for first and last name, company, E-mail address and phone number and the group screen has places for name of the group, its purpose, and a list of members and their E-mail addresses. You click on a person and get one display and on a group and get the other display.

Factory Pattern

  • This pattern is used to choose and return an instance of a class from a number of similar classes based on data you provide to the factory.

Prototype Pattern

  • This pattern copies or clones an existing class rather than creating a new instance when creating new instances is more expensive.

Singleton Pattern

  • This pattern insures that there is one and only one instance of an object, and that it is possible to obtain global access to that one instance.
  • For example, your system can have only a single point of access to a database engine.

No comments: