What is the Factory Method Pattern?

Updated Apr 28, 2026

Short answer

A creational pattern that provides an interface for creating objects in a superclass, but allows subclasses to alter the type of objects that will be created.

Deep explanation

It suggests that you replace direct object construction calls (using the new operator) with calls to a special factory method. This enables loose coupling, as the creator class doesn't need to know the exact class of the object it's creating.

Real-world example

A UI framework that renders different button styles (Windows, macOS) without the core logic knowing the exact OS button class.

Common mistakes

  • Creating a factory for every single class, resulting in unnecessary complexity and boilerplate code.

Follow-up questions

  • How does Factory Method differ from Simple Factory?

More Design Patterns interview questions

View all →