🎁 New User? Get 20% off your first purchase with code NEWUSER20 Register Now →
Menu

Categories

Programming Concepts Intermediate

What is Factory Pattern?

A creational design pattern that provides an interface for creating objects without specifying their exact classes.

The Factory pattern encapsulates object creation logic, allowing code to work with abstractions rather than concrete implementations. A Simple Factory uses a method to decide which class to instantiate. A Factory Method lets subclasses decide which class to create. An Abstract Factory creates families of related objects. Benefits include decoupling object creation from usage, easier testing (factories can return mocks), and simplified object construction when creation involves complex setup. In PHP, factories are commonly used in frameworks for creating database connections, logger instances, and service objects based on configuration.

Related Terms

Functional Programming
A programming paradigm that treats computation as the evaluation of mathematical functions, avoiding state changes and mutable data.
Algorithm
A step-by-step procedure for solving a problem or performing a computation, defined as a finite sequence of instructions.
Queue
A data structure that follows First-In-First-Out (FIFO) ordering, where elements are added at the rear and removed from the front.
Regex (Regular Expression)
A sequence of characters that defines a search pattern, used for string matching, validation, and text manipulation.
Composition over Inheritance
A design principle favoring object composition (has-a relationships) over class inheritance (is-a relationships) for code reuse.
Hash Table
A data structure that maps keys to values using a hash function, providing average O(1) time complexity for lookups, insertions, and deletions.
View All Programming Concepts Terms →