Course contentsShow
← Software Engineering
Lesson 255 of 1,9337. Creational Design PatternsFree lesson

Evaluating Trade-offs in Creational Design

Balance flexibility, testability, and simplicity when applying creational patterns versus direct instantiation approaches.

Evaluating Trade-offs in Creational Design

You'll learn: How to weigh flexibility, testability, and simplicity when deciding whether to use creational patterns or direct instantiation.

The Core Decision

Every time you create an object, you face a choice: use new MyClass() directly, or introduce a creational pattern (Factory, Builder, Singleton, etc.). Both approaches have costs and benefits. The art is knowing when the benefits justify the complexity.

Direct instantiation is simple and clear—anyone reading your code instantly understands what's being created. But it creates tight coupling: your code depends on concrete classes, making changes harder and testing more difficult.

Creational patterns add layers of abstraction. They improve flexibility (swap implementations easily), testability (inject mocks through factories), and maintainability (centralize creation logic). But they also add complexity—more classes, more indirection, and a steeper learning curve for teammates.

Think Like an Architect

Imagine building a house. You could design every room to be reconfigurable with movable walls (maximum flexibility), but that's expensive and most people don't need it. Similarly, wrapping every object creation in a factory "just in case" violates YAGNI and KISS.

Ask yourself:

  • Will this class change implementations? (If yes, consider Factory Method or Abstract Factory)
  • Is construction complex with many options? (Builder might help)
  • Do I need to swap implementations for testing? (Abstraction through factories aids testability)
  • Is the code simple enough now? (If yes, resist adding patterns prematurely)

Finding Balance

Start simple. Use direct instantiation until you feel pain—tight coupling blocking tests, or repeated complex construction logic. Then refactor toward a pattern. This respects YAGNI while keeping your design evolvable.

Key Takeaway: Choose creational patterns when flexibility and testability justify the added complexity; default to direct instantiation when simplicity serves your needs better.