Factory
A factory is a function, method, or component that creates and returns values or objects while encapsulating construction or selection logic.
Unit Testing Principles, Practices, and Patterns
A factory is a creation abstraction that constructs domain objects from input data while encapsulating instantiation or reconstruction logic.
- How it is used
- Separates domain-object reconstruction from application-service coordination.
- How deep it goes
- Explains separate classes, static methods, ORM mappings, validation, casting, and test isolation, but not factory taxonomy.
- Examples
- Uses UserFactory.Create to transform an object array into a User and applies a three-element precondition.
- What you can do after
- Build it from scratch by isolating reconstruction, validating input, constructing domain objects, and keeping services focused on coordination.
Read how Unit Testing Principles, Practices, and Patterns explains factory →
Infrastructure as Code, Patterns and Practices: With examples in Python and Terraform
A factory module is a reusable infrastructure module that generates standardized infrastructure resources from inputs and default configuration values.
- How it is used
- Standardizes reusable infrastructure resources when repeated configurations share defaults but need limited input-driven variation.
- How deep it goes
- Explains inputs, defaults, transformations, naming, composition, and pattern selection, but leaves broader module sharing and security standardization elsewhere.
- Examples
- Demonstrates network subnets, generated names, GCP load balancers, firewall rules, database systems, and Python factory classes.
- What you can do after
- Build it from scratch by turning infrastructure inputs and defaults into standardized resources, then compose factories within builder modules.
Clean Applications with Hexagonal Architecture
A construction abstraction that creates objects while encapsulating their creation logic.
- How it is used
- Uses factories as controlled creation gateways for always-valid domain entities and validated commands.
- How deep it goes
- Works through private constructors, combined validation, error returns, and standalone factories that delegate to entity factories.
- Examples
- Uses Article creation with invalid title and content, an ID-generating ArticleFactory, and PublishArticleCommand creation tests.
- What you can do after
- Build validated factory methods and standalone coordinating factories for domain objects.
Read how Clean Applications with Hexagonal Architecture explains factory →
The Art of Unit Testing 3e
A factory function is a function that creates and returns an object, value, or configured function.
- How it is used
- Creates reusable test states and centralizes construction of code under test; also configures production functions with injectable dependencies.
- How deep it goes
- Works through test helpers, higher-order factories, and constructor-change examples; defers the more advanced Object Mother pattern.
- Examples
- Uses password verifiers with passing or failing rules, fake day functions, and fake loggers to show different factory roles.
- What you can do after
- Build it from scratch: write parameterized helpers that expose test-specific state and concentrate construction changes in one place.
Software Design for Python Programmers
A factory function is a function that encapsulates creating and returning objects, often selecting among subclass types based on an input value.
- How it is used
- Encapsulates runtime selection and creation of subclass objects behind a stable construction interface.
- How deep it goes
- Defines the principle, demonstrates a Python implementation, and extends it to Factory Method while stopping short of broader implementation detail.
- Examples
- Demonstrates toy cars, model airplanes, and train sets, then applies Factory Method to varsity and intramural sports.
- What you can do after
- Apply it via Python functions or classes to remove hardcoded construction and vary object types at runtime.
Read how Software Design for Python Programmers explains factory →
Data-Oriented Programming in Java
A factory function is a function that constructs and returns an instance or structured test datum through a defined parameter interface.
- How it is used
- Selects concrete ingestion strategies and constructs locally intelligible test data.
- How deep it goes
- Shows map-backed lookup, unknown-key failure, and parameterized test-data construction, while deferring broader abstraction trade-offs.
- Examples
- Uses cloud-file ingestion with Transformers and BulkLoaders, plus account tests organized around threshold-relative factory-generated data.
- What you can do after
- Builds interface-based dispatch and focused test fixtures without repeating concrete construction details.
Read how Data-Oriented Programming in Java explains factory →
Object-Oriented Software Design in C++
A class responsible for creating and selecting instances of other classes while hiding construction details from clients.
- How it is used
- Encapsulates runtime selection and creation of subclass objects behind a shared interface.
- How deep it goes
- Explains parameterized factory functions and Factory Method delegation, but does not develop broader factory variants.
- Examples
- Uses ToyFactory with cars, airplanes, and trains, then AthleticsDept subclasses creating varsity and intramural sports.
- What you can do after
- Builds factory functions or subclass-based Factory Methods that select concrete objects while keeping clients stable.
Read how Object-Oriented Software Design in C++ explains factory →
Grokking Simplicity
A function factory is a function that creates and returns other functions, often with a shared behavior or configuration.
- How it is used
- Automates repeated function creation while standardizing cross-cutting behavior such as logging and error handling.
- How deep it goes
- Defines returned functions, wrappers, results, and argument handling, but defers broader variable-argument support to ES6 features.
- Examples
- Uses logging wrappers, saveUserData, fetchProduct, and makeAdder to demonstrate repeated creation and configured behavior.
- What you can do after
- Build reusable functions that apply consistent behavior to multiple underlying functions.
Essential TypeScript 5, Third Edition
A factory function is a function pattern that creates and returns objects or other configured values instead of requiring direct construction by the caller.
- How it is used
- Connects JSX syntax to runtime element creation and component rendering in a stand-alone web application.
- How deep it goes
- Explains compiler transformation and provides a minimal DOM implementation, but defers framework-level dynamic rendering features.
- Examples
- Uses createElement, HtmlDisplay, ProductItem, CategoryList, ProductList, DOM properties, nested components, and callbacks.
- What you can do after
- Build it from scratch with a createElement function that renders JSX into DOM elements and class-based components.
Read how Essential TypeScript 5, Third Edition explains factory →
ASP.NET Core in Action, 3e
A factory function is a function that creates and returns a configured object.
- How it is used
- Generalizes endpoint filters and configures dependency-injection service creation when runtime dependencies are needed.
- How deep it goes
- Explains endpoint inspection, filter emission, service lifetimes, and constructor-injection preference; defers endpoint metadata details.
- Examples
- Uses a fruit API’s ValidateId filter and lambda-created dependency-injection services as concrete examples.
- What you can do after
- Apply it via ASP.NET Core to tailor endpoint filters and create registered services with chosen lifetimes.
Fabulous Adventures in Data Structures and Algorithms
A factory is a construction pattern that centralizes creation of objects or data-structure instances.
- How it is used
- Uses factories to centralize memoized construction for immutable objects and deduplicate equivalent data structures.
- How deep it goes
- Builds the pattern through C# implementations, cache controls, reference identity, and memory trade-offs rather than general object-oriented taxonomy.
- Examples
- Demonstrates memoized functions, quadtrees, empty quadtree values, symbols, constants, and binary terms.
- What you can do after
- Build it from scratch using a dictionary-backed C# factory that caches immutable results and provides explicit cache control.
Read how Fabulous Adventures in Data Structures and Algorithms explains factory →
Build a Frontend Web Framework (From Scratch)
A function that creates and returns objects or other constructed values according to a defined creation procedure.
- How it is used
- Creates stateful component instances that localize state and DOM updates within a component hierarchy.
- How deep it goes
- Explains instantiation, state updates, view patching, and method binding, but does not provide production-level implementation details.
- Examples
- Uses a root component, component instances, local state, updateState(), render functions, and component DOM subtrees.
- What you can do after
- Build it from scratch by defining component state, rendering, updateState(), lifecycle behavior, and bound event handlers.
Read how Build a Frontend Web Framework (From Scratch) explains factory →
Data Pipelines with Apache Airflow, Second Edition
A factory function is a function that accepts configuration and constructs recurring workflow structures such as tasks or DAGs.
- How it is used
- Generates recurring Airflow task structures or DAGs from small configuration differences across related data sources.
- How deep it goes
- Explains configuration, task dependencies, DAG returns, and unique naming, but does not detail factory testing or deployment.
- Examples
- Uses sales and customers datasets, API ingestion, BashOperator tasks, dataset-specific paths, preprocessing scripts, and generated DAG names.
- What you can do after
- Build it from scratch by parameterizing repeated tasks or DAGs and exposing each generated DAG under a unique global name.
Read how Data Pipelines with Apache Airflow, Second Edition explains factory →
Also covered in
- Python How-To
- AI-Powered Developer: Build software with ChatGPT and Copilot
- The Joy of JavaScript
- Kotlin in Action, 2E
- Pro ASP.NET Core 7, Tenth Edition
- Idiomatic Rust
- Python Workout: 50 ten-minute exercises
- Python Workout, Second Edition
- Simple Object-Oriented Design: Create clean, maintainable applications
- Pro Angular 16
- Terraform in Depth: Infrastructure as Code with Terraform and OpenTofu
What to know first
- design patternA design pattern is a reusable, general solution structure for a recurring software design problem.
- functionA function is a callable unit of program code that performs a computation or operation, can accept inputs, and may produce a result or side effect.
- moduleA module is a cohesive unit of code or computation that groups related functionality within a larger system and defines a scope or boundary for organizing or sharing it.
- encapsulationEncapsulation is a software design principle that contains data and implementation details behind a controlled interface, restricting direct access to internal state.
Related concepts
- constantuses · A constant is a value or named binding treated as fixed rather than reassigned or modified during a computation, whether this is enforced by a language or followed by convention.
- Eitherproduces · Either is a parameterized sum type whose values hold one of two alternatives, often used to represent an error or a successful result.
- inputuses · An input is information, a value, or an action supplied to a system, program, or computation for processing or to influence its behavior.
- infrastructure resourceproduces · An infrastructure resource is an identifiable supporting component or service that provides technical capabilities on which applications or other system components depend.
- protocol factoryincludes · A protocol factory is a callable that creates and returns a protocol instance for a connection.
Questions about factory
What is factory?
A factory is a function, method, or component that creates and returns values or objects while encapsulating construction or selection logic.
Which Manning books explain factory?
Unit Testing Principles, Practices, and Patterns, Infrastructure as Code, Patterns and Practices: With examples in Python and Terraform, Clean Applications with Hexagonal Architecture, The Art of Unit Testing 3e, Software Design for Python Programmers, Data-Oriented Programming in Java, Object-Oriented Software Design in C++, Grokking Simplicity and 5 more.
What should I know before learning factory?
Manning books that teach factory usually introduce design pattern, function, module and encapsulation first.
What kinds of factory are there?
Kinds of factory include loader factory and protocol factory.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.












