Browse Java Design Patterns & Enterprise Application Architecture

Product and Creator Hierarchies in Java Factory Method

Design product and creator hierarchies that stay extensible without becoming inheritance-heavy or brittle.

Product hierarchy: The set of related types a factory method may create, usually unified by an interface or abstract base type.

Factory Method usually introduces two parallel ideas: a product side and a creator side. That can be useful, but it can also become brittle if every new variant forces a growing inheritance tree on both sides.

Keep The Product Contract Small

The product interface should represent the behavior the client actually needs, not every method the concrete classes happen to expose.

1interface NotificationSender {
2    void send(String recipient, String message);
3}

If the contract is small and stable, new products are cheaper to add and easier to test.

Creator Hierarchies Should Carry Real Shared Logic

A creator hierarchy only earns its complexity when the base class does meaningful work around the creation point:

  • validation before creation
  • stable workflow around the product
  • lifecycle steps that should not vary
  • auditing or metrics around product use

If the base class does almost nothing except declare the factory method, inheritance may be doing too much work for too little payoff.

Prefer Interfaces Over Concrete Coupling

Good Java factory-method designs usually depend on:

  • an interface or abstract type for products
  • small stable contracts
  • composition where inheritance adds little value

Bad designs often leak concrete product details back into the caller, which defeats the point of the hierarchy.

Common Mistakes

The first mistake is growing mirrored hierarchies mechanically: every new product forces a new creator subclass even when the creator adds no real behavior.

The second mistake is letting the product interface bloat because one implementation wanted extra methods.

The third mistake is confusing taxonomy with design quality. A large hierarchy can still be a weak design if the variation points are wrong.

Design Review Questions

When reviewing product and creator hierarchies, ask:

  • Is the product contract minimal and stable?
  • Does the creator base class contain real shared behavior?
  • Could composition replace some of the inheritance?
  • Are new product variants cheap to add without touching many unrelated classes?

A healthy hierarchy makes variation cheaper. An unhealthy one turns every new product into a multi-class ceremony.

Loading quiz…
Revised on Thursday, April 23, 2026