Name Some of the Design Patterns Used in the Spring Framework?

Spring Framework uses several well-known design patterns internally to provide flexibility, maintainability, and scalability. These patterns help manage object creation, dependency management, and application behavior efficiently.

Key Points: • Singleton Pattern: Used as the default bean scope, where a single bean instance is shared across the application context. • Factory Pattern: Implemented through BeanFactory and ApplicationContext to create and manage bean objects. • Proxy Pattern: Used in features such as AOP, transaction management, and security. • Template Pattern: Used in classes such as JdbcTemplate, RestTemplate, and JmsTemplate to simplify common operations. • Dependency Injection (IoC) Pattern: Used to provide dependencies to objects instead of allowing them to create dependencies themselves.

Example: When a service class is annotated with @Service, Spring typically creates a Singleton bean and manages its lifecycle through the IoC container. If transactions are enabled, Spring may create a proxy object around that bean.

Interview Tip: A concise interview answer is:

"Spring internally uses several design patterns, including Singleton, Factory, Proxy, Template, and Dependency Injection. These patterns help manage object creation, dependency injection, transaction management, and overall application architecture efficiently."