Skip to main content

Design Pattern Basics

Types of Design Patterns

0:00
LearnStep 1/4

Creational Patterns

Creational Patterns: Object Creation Mechanisms

Creational patterns deal with object creation mechanisms, trying to create objects in a manner suitable to the situation.

The Problem They Solve

Basic object creation can lead to design problems or complexity. Creational patterns solve this by controlling the creation process.

Common Creational Patterns

1. Singleton Pattern

Ensures a class has only one instance and provides a global access point to it.

python

2. Factory Method Pattern

Defines an interface for creating objects, but lets subclasses decide which class to instantiate.

python

3. Builder Pattern

Separates the construction of a complex object from its representation.

python

When to Use Creational Patterns

  • Singleton: When exactly one instance is needed (config, connection pool)
  • Factory: When creation logic is complex or might change
  • Builder: When constructing complex objects with many optional parameters
  • Prototype: When copying existing objects is cheaper than creating new ones