Pattern vs framework
Fast recall
Quick revision
Core answer
Interview-ready guide
Interview answer
A design pattern is a conceptual solution that you implement yourself.
It's a template you follow to structure your code. If you're implementing the Singleton pattern, you write the class with a private constructor, a static instance variable, and a public method to get that instance. You control every line of code.
A framework is different. It's pre-written code that provides structure and calls your methods at the right time. Spring Boot is a framework.
You don't write the dependency injection code or the web server — Spring provides that. You just annotate your classes with at-Service or at-Controller, and Spring handles instantiation and injection. The key difference is control flow.
With a pattern, you call the code — you instantiate your Singleton when you need it. With a framework, the framework calls your code — Spring creates your beans and injects them without you explicitly calling new. The important thing is that frameworks use patterns internally.
Spring uses Singleton for bean scope by default, Factory pattern in the ApplicationContext to create beans, and Proxy pattern when you use at-Transactional. So learning patterns helps you understand how Spring works under the hood. The mistake freshers make is thinking that using Spring means they understand the patterns Spring uses.
You can use Spring for years without really understanding Singleton or Proxy if you never look deeper. In an interview, show you understand the difference. ' That shows you know both what Spring is and what patterns it's built on.
Pattern vs framework
Direct Answer
A pattern is a reusable solution concept you implement yourself; a framework is pre-written code that calls your code, applying patterns for you as part of its structure.
Code Example
// PATTERN: you write and call the code yourself (Singleton)
class Config {
private static final Config INSTANCE = new Config();
private Config() {}
static Config get() { return INSTANCE; } // YOU call this
}
// FRAMEWORK: Spring writes the wiring and calls YOUR code (Inversion of Control)
@Service // Spring creates ONE instance (singleton scope)
class CartService {
private final CartRepository repo;
CartService(CartRepository repo) { // Spring injects this - you never call new
this.repo = repo;
}
}
// Rule of thumb: with a pattern your code calls in; with a framework it calls you.
Common Mistakes & Pitfalls
- Calling Spring a pattern: Saying 'Spring is a design pattern' when it's a framework that uses patterns — shows confusion about vocabulary and concepts.
- Thinking framework knowledge equals pattern knowledge: A fresher who's used Spring but can't explain the Singleton pattern Spring uses internally hasn't truly understood patterns.
- Not recognising patterns in frameworks: Using at-Transactional daily without knowing it's the Proxy pattern means you're missing opportunities to understand and apply patterns in your own code.
Check your understanding
Answer these without looking back at the article.
- Which design patterns does Spring Boot use internally?
- Can you apply design patterns without using any framework?
Looking for a structured roadmap?
Every module on this page is also part of the full Java backend interview track.