# Factory Pattern

> One function or class makes the objects. The callers need not know how.

**Field:** Software Development  
**Category:** Architecture  
**Also known as:** Factory Method, Factory Function, Factory

## Think of it like

Think of it like ordering a pizza. You say which kind, and the kitchen works out how to make it.

## Definition

The factory pattern puts the job of making objects in one place. Instead of building an object directly, code asks a factory for one and says what kind it wants. The factory decides which class to use and how to set it up. The calling code never needs to know the details. Adding a new kind then means changing only the factory.

## Example

Emma's app sends alerts by email, text or push. Her code asks the factory for the user's choice. It gets back the right sender.

## Why it matters

It keeps the hard parts of making objects in one place. So new kinds are easy to add.

## Common mistake

Adding a factory where a plain constructor would do. If there is only one kind, the factory is just one more step.

## Three principles

- **One place to make.** All objects of a family.
- **Ask by kind.** Not by class name.
- **Easy to extend.** New kind, one change.

## Related terms

- [Design Pattern](https://learn.benibix.com/term/development/design-pattern)
- [Class](https://learn.benibix.com/term/development/class)
- [Object (Programming)](https://learn.benibix.com/term/development/object)
- [Strategy Pattern](https://learn.benibix.com/term/development/strategy-pattern)
- [Builder Pattern](https://learn.benibix.com/term/development/builder-pattern)

---

Source: https://learn.benibix.com/term/development/factory-pattern
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-17
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
