Creational Patterns
   HOME

TheInfoList



OR:

In
software engineering Software engineering is a branch of both computer science and engineering focused on designing, developing, testing, and maintaining Application software, software applications. It involves applying engineering design process, engineering principl ...
, creational design patterns are
design patterns ''Design Patterns: Elements of Reusable Object-Oriented Software'' (1994) is a software engineering book describing software design patterns. The book was written by Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides, with a fore ...
that deal with
object creation Object may refer to: General meanings * Object (philosophy), a thing, being, or concept ** Object (abstract), an object which does not exist at any particular time or place ** Physical object, an identifiable collection of matter * Goal, an a ...
mechanisms, trying to create objects in a manner suitable to the situation. The basic form of object creation could result in design problems or in added complexity to the design due to inflexibility in the creation procedures. Creational design patterns solve this problem by somehow controlling this object creation.


Overview

Creational design patterns are composed of two dominant ideas. One is encapsulating knowledge about which concrete classes the system uses. Another is hiding how instances of these concrete classes are created and combined. Creational design patterns are further categorized into object-creational patterns and class-creational patterns, where object-creational patterns deal with object creation and class-creational patterns deal with class-instantiation. In greater details, object-creational patterns defer part of its object creation to another object, while class-creational patterns defer its object creation to subclasses. Five well-known design patterns that are parts of creational patterns are the * abstract factory pattern, which provides an interface for creating related or dependent objects without specifying the objects' concrete classes. * builder pattern, which separates the construction of a complex object from its representation so that the same construction process can create different representations. *
factory method pattern In object-oriented programming, the factory method pattern is a software design pattern, design pattern that uses factory methods to deal with the problem of object creation, creating objects without having to specify their exact class (computer pr ...
, which allows a class to defer instantiation to subclasses. * prototype pattern, which specifies the kind of object to create using a prototypical instance, and creates new objects by cloning this prototype. *
singleton pattern In object-oriented programming, the singleton pattern is a software design pattern that restricts the instantiation of a class to a singular instance. It is one of the well-known "Gang of Four" design patterns, which describe how to solve recur ...
, which ensures that a class only has one instance, and provides a global point of access to it.


Definition

The creational patterns aim to separate a system from how its objects are created, composed, and represented. They increase the system's flexibility in terms of the what, who, how, and when of object creation.


Usage

As modern software engineering depends more on
object composition In computer science, object composition and object aggregation are closely related ways to combine objects or data types into more complex ones. In conversation, the distinction between composition and aggregation is often ignored. Common ki ...
than class inheritance, emphasis shifts away from hard-coding behaviors toward defining a smaller set of basic behaviors that can be composed into more complex ones. Hard-coding behaviors are inflexible because they require overriding or re-implementing the whole thing in order to change parts of the design. Additionally, hard-coding does not promote reuse and makes it difficult to keep track of errors. For these reasons, creational patterns are more useful than hard-coding behaviors. Creational patterns make design become more flexible. They provide different ways to remove explicit references in the concrete classes from the code that needs to instantiate them. In other words, they create independency for objects and classes. Consider applying creational patterns when: * A system should be independent of how its objects and products are created. * A set of related objects is designed to be used together. * Hiding the implementations of a class library or product, revealing only their interfaces. * Constructing different representation of independent complex objects. * A class wants its subclass to implement the object it creates. * The class instantiations are specified at run-time. * There must be a single instance and client can access this instance at all times. * Instance should be extensible without being modified.


Structure

Below is a simple class diagram that most creational patterns have in common. Note that different creational patterns require additional and different participated classes. Participants: * Creator: Declares object interface. Returns object. * ConcreteCreator: Implements object's interface.


Examples

Some examples of creational design patterns include: * Abstract Factory pattern: a class requests the objects it requires from a factory object instead of creating the objects directly *
Factory method pattern In object-oriented programming, the factory method pattern is a software design pattern, design pattern that uses factory methods to deal with the problem of object creation, creating objects without having to specify their exact class (computer pr ...
: centralize creation of an object of a specific type choosing one of several implementations * Builder pattern: separate the construction of a complex object from its representation so that the same construction process can create different representations * Dependency Injection pattern: a class accepts the objects it requires from an injector instead of creating the objects directly * Lazy initialization pattern: tactic of delaying the creation of an object, the calculation of a value, or some other expensive process until the first time it is needed * Object pool pattern: avoid expensive acquisition and release of resources by recycling objects that are no longer in use * Prototype pattern: used when the type of objects to create is determined by a prototypical instance, which is cloned to produce new objects *
Singleton pattern In object-oriented programming, the singleton pattern is a software design pattern that restricts the instantiation of a class to a singular instance. It is one of the well-known "Gang of Four" design patterns, which describe how to solve recur ...
: restrict instantiation of a class to one object


See also

* Constructor * Behavioral pattern *
Concurrency pattern In software engineering, concurrency patterns are those types of design patterns that deal with the multi-threaded programming paradigm. Examples of this class of patterns include: * Active object * Balking pattern * Barrier * Double-check ...
* Structural pattern


References

{{DEFAULTSORT:Creational Pattern Software design patterns