Design Patterns Interview Questions
Design Patterns Fundamentals
- What are design patterns? What is their purpose?
- What are the categories of design patterns?
- What are creational patterns, structural patterns, and behavioral patterns?
- What are the six principles of design patterns?
- What is the Single Responsibility Principle (SRP)?
- What is the Open-Closed Principle (OCP)?
- What is the Liskov Substitution Principle (LSP)?
- What is the Dependency Inversion Principle (DIP)?
- What is the Interface Segregation Principle (ISP)?
- What is the Law of Demeter (LoD)?
Creational Patterns
Singleton Pattern
- What is the Singleton pattern? What are its application scenarios?
- What are the implementation methods of Singleton pattern?
- What is eager initialization Singleton? What are its pros and cons?
- What is lazy initialization Singleton? How to make it thread-safe?
- What is Double-Checked Locking (DCL) Singleton? Why use volatile?
- What is static inner class Singleton?
- What is enum Singleton? Why is enum recommended for implementing Singleton?
- How to prevent Singleton pattern from being broken by reflection?
- How to prevent Singleton pattern from being broken by serialization?
- Is Spring’s Singleton Bean thread-safe?
Factory Pattern
- What is Simple Factory pattern? What are its pros and cons?
- What is Factory Method pattern? What are the differences from Simple Factory?
- What is Abstract Factory pattern? What are the differences from Factory Method?
- What are the application scenarios of Factory pattern?
- Where does Spring use Factory pattern?
Builder Pattern
- What is Builder pattern? What is its purpose?
- What are the differences between Builder pattern and Factory pattern?
- What are the application scenarios of Builder pattern?
- What design pattern does StringBuilder use?
Prototype Pattern
- What is Prototype pattern? What is its purpose?
- What are shallow copy and deep copy?
- How to implement deep copy?
- What are the application scenarios of Prototype pattern?
- Is Object’s clone() method shallow copy or deep copy?
Structural Patterns
Proxy Pattern
- What is Proxy pattern? What is its purpose?
- What are the categories of Proxy pattern?
- What is static proxy? What are its pros and cons?
- What is dynamic proxy? What are the implementation methods?
- What is the implementation principle of JDK dynamic proxy?
- What is the implementation principle of CGLIB dynamic proxy?
- What are the differences between JDK dynamic proxy and CGLIB proxy?
- What design pattern does Spring AOP use?
- What are the application scenarios of Proxy pattern?
Adapter Pattern
- What is Adapter pattern? What is its purpose?
- What are the categories of Adapter pattern?
- What are the differences between Adapter pattern and Decorator pattern?
- What are the application scenarios of Adapter pattern?
- What pattern does HandlerAdapter in Spring MVC use?
Decorator Pattern
- What is Decorator pattern? What is its purpose?
- What are the differences between Decorator pattern and inheritance?
- What are the application scenarios of Decorator pattern?
- What design pattern does Java I/O stream use?
Bridge Pattern
- What is Bridge pattern? What is its purpose?
- What are the application scenarios of Bridge pattern?
- What design pattern does JDBC driver use?
Facade Pattern
- What is Facade pattern? What is its purpose?
- What are the application scenarios of Facade pattern?
- What are the pros and cons of Facade pattern?
Composite Pattern
- What is Composite pattern? What is its purpose?
- What are the application scenarios of Composite pattern?
- What design pattern does file system use?
Flyweight Pattern
- What is Flyweight pattern? What is its purpose?
- How does Flyweight pattern reduce memory usage?
- What are the application scenarios of Flyweight pattern?
- What design pattern does String constant pool use?
- What design pattern does Integer cache use?
Behavioral Patterns
Template Method Pattern
- What is Template Method pattern? What is its purpose?
- What are the application scenarios of Template Method pattern?
- What design pattern does AbstractList use?
- Where does Spring use Template Method pattern?
Strategy Pattern
- What is Strategy pattern? What is its purpose?
- What are the differences between Strategy pattern and Simple Factory pattern?
- What are the application scenarios of Strategy pattern?
- How to eliminate if-else?
- What design pattern does Comparator use?
Observer Pattern
- What is Observer pattern? What is its purpose?
- What are the roles in Observer pattern?
- What are the application scenarios of Observer pattern?
- What design pattern does Spring’s event mechanism use?
- What design pattern is used in MVC pattern?
Chain of Responsibility Pattern
- What is Chain of Responsibility pattern? What is its purpose?
- What are the application scenarios of Chain of Responsibility pattern?
- What design pattern does Servlet’s Filter use?
- What design pattern does Spring’s interceptor use?
Iterator Pattern
- What is Iterator pattern? What is its purpose?
- What are the application scenarios of Iterator pattern?
- What design pattern does Java Collections Framework use?
Command Pattern
- What is Command pattern? What is its purpose?
- What are the application scenarios of Command pattern?
- What design pattern does Runnable interface use?
State Pattern
- What is State pattern? What is its purpose?
- What are the differences between State pattern and Strategy pattern?
- What are the application scenarios of State pattern?
- What design pattern can be used for order status transitions?
Memento Pattern
- What is Memento pattern? What is its purpose?
- What are the application scenarios of Memento pattern?
- How to implement undo and redo functionality?
Mediator Pattern
- What is Mediator pattern? What is its purpose?
- What are the application scenarios of Mediator pattern?
- What design pattern concept does MQ message queue use?
Visitor Pattern
- What is Visitor pattern? What is its purpose?
- What are the application scenarios of Visitor pattern?
Interpreter Pattern
- What is Interpreter pattern? What is its purpose?
- What are the application scenarios of Interpreter pattern?
- What design pattern does Spring’s EL expression use?
Comprehensive Questions
- Which design patterns have you used in real projects?
- How to choose appropriate design patterns?
- What problems can overuse of design patterns cause?
- What are the differences between design patterns and architectural patterns?
- What design patterns are used in the Spring framework?
Last updated on