0Pricing
Clean Architecture & Design Patterns in Practice · Lesson

Dependency Injection as a Creational Technique

Learn how dependency injection complements creational patterns by moving object construction out of consumers and into a central composition point.

Why Another Creational Approach?

Classic creational patterns like Factory and Builder centralize how objects are built. Dependency Injection (DI) centralizes where they are wired together.

  • A class no longer creates its own collaborators.
  • Instead, collaborators are supplied from outside.

This is the natural endpoint of the creational journey: removing the new keyword from business logic entirely.

The Problem DI Solves

Consider a service that builds its own dependency:

The service is now hard-wired to a concrete class. You cannot swap it for a test double or an alternative implementation without editing the service.

class ReportService {
    private final MySqlDatabase db = new MySqlDatabase();
    void run() { db.query("..."); }
}

All lessons in this course

  1. Singleton and Factory Method
  2. Abstract Factory and Builder
  3. Prototype and Object Pool
  4. Dependency Injection as a Creational Technique
← Back to Clean Architecture & Design Patterns in Practice