100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace

Creational Design Patterns Cheat Sheet

Creational Design Patterns Cheat Sheet

Singleton, Factory Method, and Builder patterns for controlling how and when objects get created, with trade-offs for each approach.

2 PagesIntermediateMar 22, 2026

Singleton Pattern

Ensuring a class has exactly one shared instance.

python
class Singleton:    _instance = None    def __new__(cls, *args, **kwargs):        if cls._instance is None:            cls._instance = super().__new__(cls)        return cls._instances1 = Singleton()s2 = Singleton()s1 is s2  # True, same instance# Simpler Pythonic alternative: a module is already a singleton,# or use functools.lru_cache(maxsize=None) on a factory function.

Factory Method

Delegating object instantiation to a function based on input.

python
from abc import ABC, abstractmethodclass Notifier(ABC):    @abstractmethod    def send(self, message): ...class EmailNotifier(Notifier):    def send(self, message): print(f"Email: {message}")class SMSNotifier(Notifier):    def send(self, message): print(f"SMS: {message}")def notifier_factory(channel: str) -> Notifier:    if channel == "email":        return EmailNotifier()    if channel == "sms":        return SMSNotifier()    raise ValueError(f"unknown channel: {channel}")notifier_factory("email").send("Welcome!")  # Email: Welcome!

Builder Pattern

Constructing a complex object step by step with method chaining.

python
class Pizza:    def __init__(self):        self.toppings = []        self.size = None    def __repr__(self):        return f"Pizza({self.size}, {self.toppings})"class PizzaBuilder:    def __init__(self):        self._pizza = Pizza()    def size(self, size):        self._pizza.size = size        return self          # enables method chaining    def add_topping(self, topping):        self._pizza.toppings.append(topping)        return self    def build(self):        return self._pizzapizza = (PizzaBuilder()         .size("large")         .add_topping("cheese")         .add_topping("mushroom")         .build())

Creational Pattern Catalog

One-line definitions of the classic Gang of Four creational patterns.

  • Singleton- Ensure a class has only one instance and provide a global point of access to it
  • Factory Method- Define an interface for creating an object, but let subclasses decide which class to instantiate
  • Abstract Factory- Provide an interface for creating families of related objects without specifying their concrete classes
  • Builder- Separate the construction of a complex object from its representation, using step-by-step configuration
  • Prototype- Create new objects by copying an existing instance instead of instantiating from scratch
Pro Tip

Singleton is one of the most overused patterns — it introduces hidden global state and makes unit testing harder because you can't easily swap in a test double. Prefer dependency-injecting a single shared instance over hardcoding a Singleton class.

Was this cheat sheet helpful?

Explore Topics

#CreationalDesignPatterns#CreationalDesignPatternsCheatSheet#Programming#Intermediate#SingletonPattern#FactoryMethod#BuilderPattern#CreationalPatternCatalog#OOP#Functions#CheatSheet#SkillVeris
Advertisement
Sri Hayavadhana Info-Tech

Professional Web Designing Services

  • Responsive Websites
  • E-commerce Solutions
  • SEO Friendly Design
  • Fast & Secure
  • Support & Maintenance
Get a Free Quote

Share this Cheat Sheet