Extend factory-based creation in Java without turning each new product into a brittle inheritance ceremony.
Extending a factory: Adding new creation options without forcing invasive changes across existing clients and creation code.
Factories are often introduced in the name of extensibility, but the real test comes later. Can a new product type be added without changing half the system? Can product-specific configuration stay local? Can callers remain stable?
In Java, extension usually happens in one of two ways:
Subclassing fits when the creator already owns a meaningful workflow. Strategy or registry approaches fit better when extension should stay pluggable.
Clients should depend on the product contract, not on the extension mechanism itself. A caller ideally does not care whether a product came from:
If extension leaks into the caller, the factory is not buying much isolation.
The Open/Closed Principle is not about never changing code. It is about putting the likely change point in the right place. For factories, that means the creation mechanism should make typical new variants cheap while keeping existing callers stable.
A practical smell is when every new product requires:
That means the extension seam is probably wrong.
When reviewing factory extensibility, ask:
Good extensibility feels local. Bad extensibility advertises flexibility while distributing change cost across the codebase.