Java Zero to All All questionsPractise free
Interview questions › Design Patterns in Java › Creational Design Patterns

In a Spring application, how often do you actually write GoF creational patterns by hand, and why?

Level II · JuniorCreational Design Patterns
Short answer

Rarely, because the container is the factory and the singleton manager: @Component gives you managed-singleton scope, @Bean methods are factory methods, @Profile/@Conditional plus @Qualifier select families like an abstract factory, and @Scope('prototype') gives fresh instances.

Explanation

You still write an explicit factory when you must build objects from runtime data the container can't know in advance — that's where ObjectProvider<T> or a small FactoryBean earns its place. The senior point is knowing the patterns so you can recognize what the container does for you and spot the gap it doesn't cover.

Common mistakes
  • Hand-rolling singletons and factories in Spring apps.
  • Not seeing that Spring beans are singletons by default.

Can you say this out loud in two minutes? Drill it in a timed mock interview, with flashcards and runnable code for Creational Design Patterns.

Practise free

More on Creational Design Patterns