One varying product
Factory Method is usually the simplest fit when the design pressure is selection of one product type.
Factory Method, Abstract Factory, and Builder are often confused because they all influence creation. The cleanest way to distinguish them is by asking what is actually hurting. If one product varies, Factory Method is often enough. If several related products must vary together, Abstract Factory is stronger. If assembly itself is the pain, Builder is usually the better fit.
In a Java commerce system, payment gateway selection, environment-specific platform bundles, and receipt assembly can all look like creation problems on the surface, yet they want different responses.
These patterns overlap only at the surface level of “object creation.” Underneath, they solve different forces. Factory Method localizes selection of a single product. Abstract Factory coordinates families. Builder clarifies assembly.
For Java developers, this distinction matters because the wrong choice often leads to unnecessary abstraction. An Abstract Factory around one product is heavier than needed. A Builder used to model product families confuses the intent. A Factory Method used where assembly is the real problem just moves complexity around.
Choose based on the force, not the shared category label.
Factory Method is usually the simplest fit when the design pressure is selection of one product type.
Abstract Factory is stronger when several related products must vary together consistently.
Builder is better when creation is multi-step, optional, or awkward rather than family-based.
package org.javaomnibus.ecommerce.gof.creational;
public final class CreationPressures {
PaymentGateway gatewayFor(String method) { return null; }
CommercePlatformFactory platformFactoryFor(String region) { return null; }
OrderReceipt.Builder receiptBuilder(String orderId, String email) { return null; }
}
| Pattern | Best force | Typical Java example | Main risk |
|---|---|---|---|
| Factory Method | One product varies | Payment gateway selection | Adding needless indirection for stable creation |
| Abstract Factory | Families vary together | Platform bundle per environment or partner profile | Over-modeling a weak family concept |
| Builder | Construction process is awkward | Readable receipt or request assembly | Adding ceremony to simple objects |
A comparison page simplifies choice, but the actual code context still matters. The goal is to narrow the choice responsibly, not to replace judgment with a rule chart.