Scrivio Interview library
LeadershipPrincipal6 min read · updated 12 November 2026

The GoF creational patterns were described in 1994 for C++ and Smalltalk. Which of them remain relevant in modern Java with DI containers, records, lambdas and modules, and how would you teach this to senior engineers?

In modern Java, singleton is mostly replaced by container scopes, with static singletons kept for stateless utilities; factory method thrives as static factories and as lambdas such as Supplier; and builder remains common for immutable objects with many optional values. Abstract factory and prototype are rare, because configuration and immutability usually do their job. I would teach the patterns as a shared vocabulary for recurring problems rather than as targets, ask engineers to prefer the simplest construct the language now offers, and review designs for pattern overuse as well as underuse.

Why this question is asked

The Design Patterns book is more than thirty years old, and its examples were written in C++ and Smalltalk, long before Java had generics, lambdas, dependency injection containers or records. Yet its vocabulary still runs through code reviews and interviews. Senior engineers are expected to know which ideas survived, in which new form, and to help others use them with judgement instead of ritual. In this answer, we will recall what the creational patterns were solving, see how modern Java changed each one, look at the ones that were absorbed and the ones that live on in new forms, and then discuss how to teach this to senior engineers.

1What the Creational Patterns Were Solving

The five GoF creational patterns all answer one question: how do we create objects without tying the calling code to concrete classes and construction details? Each answers it for a different situation. When there must be exactly one instance, singleton gives it a global access point. When a superclass needs an object whose class only a subclass knows, factory method lets the subclass decide. When several objects must come from the same family, abstract factory creates the whole family through one object. When an object has many parts, builder assembles it step by step, and when creating from scratch is expensive, prototype copies an existing object instead.

In C++ and Smalltalk in 1994, the language offered little help with these concerns, so the patterns were the help. Modern Java and its frameworks have since taken over several of these jobs, which is why the patterns' relevance has changed unevenly.

2How Modern Java Changed Each Pattern

A useful exercise is to ask, for each pattern, which language or platform feature now does part of its job. The answer differs a lot between patterns.

The creational patterns in modern Java
PatternWhat took over part of its jobRelevance today
SingletonDI container scopesLow; static only for stateless utilities
Factory methodStatic factories, Supplier lambdasHigh, in lighter forms
Abstract factoryProfiles, conditional configurationRare; real for pluggable families
BuilderRecords help, but not optional valuesHigh for many optional values
PrototypeImmutable objects, copy constructorsRare

Notice the pattern in this table: where a container or language feature solves the problem, the hand-written pattern faded; where the problem is about API design for callers, the pattern survived, often in a lighter form.

3Singleton and Abstract Factory: Mostly Absorbed

A Spring or Jakarta EE container gives us one instance per bean definition and injects it through constructors. That keeps the single instance without the static access that makes classic singletons hard to test. So in application code, a hand-written singleton is usually a smell, except for stateless utilities such as a pre-compiled regular expression or a comparator.

Abstract factory is similar. Its classic use, choosing a consistent family of implementations, is now often done by configuration: a Spring profile or a @ConditionalOnProperty selects a set of beans for AWS or for a local test setup. Hand-written abstract factories still appear in libraries and platform code, for example the JDK's XML parser factories, where implementations are discovered at run time, but they are rare in services.

4Factory Method and Builder: Alive in New Forms

Factory method survived best, though it changed shape. Static factory methods, such as List.of, Optional.of and Duration.ofSeconds, give names to creation, can return cached instances or hidden implementation classes, and are now the normal way JDK APIs create objects. And a lambda is often a factory: a Supplier<T> passed to a method is a factory method without a class hierarchy.

Java
// Static factory: named, may return a hidden implementation
List<String> regions = List.of("eu", "us"); // ImmutableCollections$List12
// Supplier as a lightweight factory
Map<String, List<Order>> byCustomer = new HashMap<>();
byCustomer.computeIfAbsent("c-17", k -> new ArrayList<>()).add(order);
ThreadLocal<DateTimeFormatter> fmt = ThreadLocal.withInitial(() -> DateTimeFormatter.ISO_DATE);
// Builder: still the clearest way to set many optional values
HttpRequest req = HttpRequest.newBuilder(URI.create("https://api/orders"))
.timeout(Duration.ofSeconds(5))
.header("Accept", "application/json")
.GET()
.build();

Builder is alive for a simple reason: Java still has no named or default parameters. Records make small immutable types trivial, but a type with eight optional settings is unreadable as a constructor call. The JDK's own HttpClient and HttpRequest use builders for exactly this. Prototype, meanwhile, has faded because immutable objects can be shared instead of copied, and Object.clone() is widely considered awkward; a copy constructor or a static copyOf method does the job when needed.

5Teaching It to Senior Engineers

Senior engineers usually know the patterns; the risk is using them as goals. A design that introduces an AbstractPaymentClientFactoryProvider for two implementations shows overuse, and so does a builder for a record with two fields. The opposite risk is underuse: a 300-line switch statement that grows with every new provider, where a small factory interface would make each addition a new class.

So I would teach problem first. Each session starts with a real piece of our code, names the problem (too many constructor parameters, a growing switch, hidden global state), and asks what the simplest construct is that solves it in Java 25: a record, a static factory, a lambda, a bean, or, if needed, the full pattern. The pattern name is then used as vocabulary to describe the solution in reviews, not as the reason for it. Design reviews should ask both questions: is this pattern earning its cost, and is there a recurring problem here that a known pattern would make clearer?

Step throughChoosing a creation approach in review
  1. What problem does the creation code have?name it first
  2. Can a plain constructor or record express it clearly?
    YesUse itNoContinue
  3. Is a static factory or lambda enough?
    YesUse itNoContinue
  4. Does the container already solve it (scope, profile)?
    YesConfigure itNoUse the full pattern, and say why

4 steps in order. Play them, or step through them one at a time.

The pattern is the last step, not the first.

6Follow-up questions

Is the singleton pattern an anti-pattern now?

The global static access is what causes most problems, because it hides dependencies and shares state across tests. The idea of a single instance is fine and very common, but in applications the container should provide it. A stateless static utility is still acceptable.

Do records replace builders?

Not fully. Records remove boilerplate for small immutable types, and a compact constructor can validate. But Java has no named or default parameters, so a record with many optional components is still awkward to construct, and a builder on top of a record is a common, sensible combination.

How do you spot pattern overuse in a review?

Look for abstractions with a single implementation and no planned second one, factories that only call one constructor, and class names longer than the logic they contain. Ask what problem each layer solves today; if the answer is a hypothetical future, the simpler version usually wins.

7Conclusion

In this answer, we saw that the creational patterns solve the problem of creating objects without tying callers to concrete classes, and that modern Java absorbed some of them. Container scopes replaced most singletons, configuration replaced most abstract factories, and immutability replaced prototype, while factory method lives on as static factories and Supplier lambdas and builder remains the answer to many optional values. Teaching them as problem-first vocabulary, and reviewing for both overuse and underuse, keeps their value without the ritual.

What to say in the interviewAbout 80 seconds aloud

Open with

I would say the problems the patterns describe are still with us, but modern Java solved several of them in other ways. Singleton is mostly handled by container scopes now: Spring gives one instance per bean definition and injects it, which avoids the hidden static access, so I only keep static singletons for stateless utilities.

Then, if they want more

Factory method is the strongest survivor, mainly as static factories like List.of, Optional.of or Duration.ofSeconds, which have names and can return cached or hidden implementations, and as lambdas, since a Supplier is really a lightweight factory.

Builder is still common because Java has no named or default parameters; HttpRequest.newBuilder is a good example, and builders on top of records are fine. Abstract factory and prototype are rare in services: profiles and conditional configuration pick families of beans, and immutable objects can be shared instead of cloned.

To teach this to senior engineers, I would start from real code and a named problem, ask for the simplest construct the language offers today, and use pattern names as shared vocabulary rather than as goals.

And in design reviews I would look for both overuse, like factories for a single implementation, and underuse, like a switch that grows with every new provider.

About this answer

Last updated
12 November 2026
Versions it names
Java 25
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the official documentation for the version you use. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "The GoF creational patterns were described in 1994 for C++ and Smalltalk. Which of them...": https://scrivio-interview-library.netlify.app/java/creational-patterns/31f22e4f27/