Why not just call the constructor?
A pull request adds an API through which mortgage brokers can submit applications to a lender, and with it a new class. A reviewer leaves one comment: "Why do we need MortgageApplicationFactory? new MortgageApplication(...) works." It is a fair question, and sometimes the honest answer is that you don't. If creating an object means storing its arguments, each of which has already checked itself, a constructor is enough. A factory earns its place when assembling the object needs rules or other objects. This lender's applications need both.
What it takes to open an application
An application here gets a number from the lender's sequence, such as MA-2026-004817. It has one or two applicants, never more. The amount has to fit the chosen product: the five-year fixed-rate product lends up to 90% of the property's value, so on a home valued at €320,000 it lends at most €288,000. The term is at most 35 years, and under this lender's policy the oldest applicant must be no older than 75 when it ends. The application starts in Submitted, with a list of documents to collect that depends on how each applicant earns: payslips for an employee, two years of accounts for someone self-employed.
Those are the application's invariants at creation: facts that must be true of every application the moment it exists. Until this pull request they lived in the web form's controller, which built the application with new and a row of setters, checked the amount on the way and generated the document list at the end. The broker API is a second way to start an application. Copying the controller's code into it would leave two copies of these rules to keep identical, and every application would be only as complete as the copy that built it.
One place that says yes
So the pull request moves creation into one object. MortgageApplicationFactory.submit(applicants, property, product, amount, term) either returns a complete application, with its number, its status and its document list, or refuses with the rule that failed, and the web form and the broker API both call it. Domain-Driven Design calls such an object a Factory: it encapsulates the creation of a complex aggregate, or sometimes of a complex value object, and enforces all of its creation invariants up front, so the object is valid from birth. No caller is handed a half-built application to finish.
Why not put all this in the constructor? Because it needs things an application should not reach for. The number comes from a sequence in the database, the age rule needs today's date, and the limits belong to the product. A constructor that calls a sequence ties the aggregate to infrastructure and makes creation hard to test in isolation. The factory takes those collaborators. The application's own constructor stays plain and out of reach of ordinary callers (the repository's rebuild, below, aside), so a new entry point cannot skip the factory.
The name echoes Factory Method, the Gang of Four pattern, which is about polymorphic instantiation: letting a subclass decide which class to create. Here there is one class, MortgageApplication, and the point is domain integrity.
Nor does the factory have to be a class of its own. When one object already holds most of what creation needs, a method on it can do the job: product.openApplication(applicants, property, amount, term) would check against limits the product already holds, and an aggregate root creates its own parts the same way, as application.addApplicant(person) creates an applicant inside the application. This lender kept a separate factory because opening an application draws on the product, the number sequence, the date and the document rules for each kind of income, and putting all of that on the product would teach it about sequences and payslips.
The application service asks the factory, which reads the product's limits and returns a valid application or refuses. Later loads come from the repository, which rebuilds the stored application without the creation rules.
Behind the form and the broker API, an application service calls the factory, adds the result to the repository and commits, the coordinator Application Service (DDD) describes.
Loading is not creating
Application MA-2026-004817 was submitted on 28 October for €281,600 on that €320,000 home, 88% of its value. On 1 November the lender lowers the five-year fixed product's limit to 85% for new applications. The next morning an underwriter opens the application, and the repository loads it.
Built by calling the factory, it would go wrong three ways: the amount check would refuse an application the lender already accepted, the sequence would hand out a new number, and a fresh document list would replace the one where the payslips are already marked as received. Loading is reconstitution: rebuilding an object that already exists from what was stored, with its own number, status and history. It does not run the creation rules again, since they were checked at creation; the rules that must hold after every change are enforced by the application's own methods whenever something changes. If stored data breaks an invariant that applies to its state, that is an inconsistency to report and investigate, perhaps a pending migration, not an application to refuse. Repository shows how the stored rows become an application again.
What the factory should not do
- Clean up the input. Parsing the broker API's date formats or trimming spaces from a postcode inside the factory mixes two creation-time jobs: making sense of a request and enforcing the aggregate's invariants. Parsing belongs where the request arrives, and a rule about one value, such as a postcode's format or an amount that cannot be negative, belongs to that value's type: Value Object covers making an invalid value impossible to construct.
- Leave another way in. A public constructor or setters that let a caller skip the creation rules let a third entry point build an invalid application. In this design only the factory creates applications, and the repository keeps its own path for rebuilding stored ones.
- Stand in for a builder. A long list of optional parts supplied one at a time is a job for Builder, which on its own does not decide which applications this lender may open.
A factory among the building blocks
The DDD Tactical Building Blocks Challenge puts the factory beside the other tactical blocks around one use case, and asks you to "Model a Factory assembling new aggregates in a valid state". Take this lender's submission or a creation from your own domain where the new aggregate depends on a policy, a schedule or a sequence. Write the creation invariants on the factory's card, connect what supplies its rules into it, and draw the repository's path to the aggregate apart from the factory's, since loading does not create. Then replay this article's pull request on your design: add a second way in, say applications arriving in a nightly file from a partner bank, and route it. It should reach the same factory, without a copy of the creation rules.