Browse Java Design Patterns & Enterprise Application Architecture

Parameterized Factories in Java

Use parameterized factories when selection logic is simple enough for one creation component and does not need a full class hierarchy.

Parameterized factory: A factory that chooses which product to create based on an input parameter instead of an overridable creator method.

Many Java codebases do not need a full Factory Method hierarchy. They need one central place that maps a mode, type, enum, or configuration value to a concrete implementation. That is where parameterized factories can be the better trade.

When This Is Better Than Factory Method

A parameterized factory is usually a stronger choice when:

  • selection is based on explicit input
  • there is no meaningful creator hierarchy
  • the workflow around creation is minimal
  • the caller benefits from one obvious factory entry point
 1enum ExportFormat {
 2    PDF,
 3    HTML
 4}
 5
 6final class DocumentFactory {
 7    Document create(ExportFormat format) {
 8        return switch (format) {
 9            case PDF -> new PdfDocument();
10            case HTML -> new HtmlDocument();
11        };
12    }
13}

This is still disciplined creation. It just avoids subclassing when subclassing is not buying anything.

When It Starts To Strain

Parameterized factories weaken when:

  • selection logic becomes huge or scattered
  • the parameters begin encoding too many unrelated creation rules
  • created products need different surrounding workflows
  • extension requires constantly editing one central branching class

At that point, a more explicit factory-method or strategy-based design may age better.

Keep Parameters Honest

The input should represent a real selection concern. Good inputs are things like:

  • an enum of supported product kinds
  • a configuration profile
  • a version or protocol variant

Bad inputs are vague boolean flags or overloaded parameter sets that hide multiple different creation axes.

Design Review Questions

When reviewing a parameterized factory, ask:

  • Is there really one selection axis?
  • Is the branching still readable?
  • Would a registry or pluggable strategy make extension easier?
  • Is the factory centralizing creation clearly, or turning into a god object?

Parameterized factories are useful because they are often the smallest pattern that works. The mistake is keeping them after the variation space has outgrown them.

Loading quiz…
Revised on Thursday, April 23, 2026