Creational Patterns  «Prev  Next»

Creational Design Patterns

In software engineering, creational design patterns are design patterns that deal with object creation mechanisms, trying to create objects in a manner suitable to the situation. The basic form of object creation could result in design problems or added complexity to the design. Creational design patterns solve this problem by somehow controlling this object creation. Creational design patterns are composed of two dominant ideas.
  1. One is encapsulating knowledge about which concrete classes the system use.
  2. 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 objection creation to subclasses.
Five well-known design patterns that are parts of creational patterns are listed as follows:
Creational pattern structure
Creational pattern structure

Key Characteristics of Creational Design Patterns

Creational design patterns focus on simplifying and managing the process of object creation in software systems. They abstract the instantiation mechanism, ensuring systems are more flexible, maintainable, and scalable.
  1. Abstraction of Object Creation:
    • Separates object creation from its usage.
    • Abstracts instantiation logic into dedicated components or classes.
  2. Encapsulation of Instantiation Logic:
    • Shields client code from complexities involved in creating objects.
    • Reduces dependencies and coupling between classes.
  3. Flexibility and Extensibility:
    • Makes it easy to extend and introduce new classes or types without major modifications.
    • Facilitates code that easily adapts to changing requirements.
  4. Reusability:
    • Encourages the reuse of object creation logic across different parts of the system.
    • Reduces redundancy and increases maintainability.
  5. Controlled Object Lifecycle:
    • Provides greater control over object creation processes, such as controlling the number of instances (e.g., Singleton).
    • Manages complex initialization steps effectively.
  6. Hide Complexity:
    • Simplifies complex object creation processes into easy-to-use interfaces or methods.
    • Improves readability and usability.
  7. Decoupling Clients from Concrete Classes:
    • Promotes programming to interfaces or abstract classes rather than concrete implementations.
    • Enables easier testing and replacement of implementations.

Common Creational Patterns Include:
  • Singleton: Ensures a class has only one instance and provides a global point of access.
  • Factory Method: Defines an interface for creating objects, letting subclasses decide which class to instantiate.
  • Abstract Factory: Provides an interface for creating families of related or dependent objects without specifying their concrete classes.
  • Builder: Separates the construction of a complex object from its representation, allowing the same construction process to create various representations.
  • Prototype: Creates new objects by copying or cloning existing objects, thus avoiding costly creation steps.

Creational patterns are crucial for managing complexity in object-oriented design, especially in scenarios where the direct use of constructors is problematic or limiting.
  1. Abstract factory pattern, which provides an interface for creating related or dependent objects without specifying the objects' concrete classes.
  2. Builder pattern, which separates the construction of a complex object from its representation so that the same construction process can create different representation.
  3. Factory method pattern, which allows a class to defer instantiation to subclasses.
  4. Prototype pattern, which specifies the kind of object to create using a prototypical instance, and creates new objects by cloning this prototype.
  5. Singleton pattern, which ensures that a class only has one instance, and provides a global point of access to it.

Title: creational-patterns-3

Title: five-patterns

Title: three-design-patterns

Title: tree

Gang of Four Patterns