1.

Which design patterns used in Spring framework?

Answer»

Design patterns help to follow good practices of programming. Spring framework, as one of the most popular web frameworks, also uses some of them.

The proxy pattern is used heavily in AOP and remoting.

Spring class “org.springframework.aop.framework.ProxyFactoryBean” uses a proxy design pattern. It builds the AOP proxy based on Spring beans.

The proxy provides a placeholder for another bean to control access to it.

In the Singleton design pattern, only a single instance of the class is returned on any number of request to create an object of the class. In the spring framework, the Singleton is the default scope and the spring container creates and RETURNS an exactly single instance of the class per spring container. Spring container cache the singleton bean and return the same bean upon any request for the bean. It is recommended to use the singleton scope for stateless beans.

  • Factory design pattern

It provides a public static factory method to initialize the object.

The Spring framework uses the factory design pattern to create the bean using BeanFactory Container and ApplicationContext Container.

  • Template Design Pattern

The pattern used heavily to reduce boilerplate code. For example JdbcTemplate, JmsTemplate, JpaTemplate.

  • Model View Controller Pattern

Spring MVC is using the pattern in the web application. The controller is POJO instead of servlet, which makes controller testing easier. The controller returns logical view name and RESPONSIBILITY to resolve the view is on ViewResolver, which makes it easier to REUSE controller for different view technologies.

  • Front Controller Pattern

Spring dispatcherservlet dispatches all incoming request to the mapped controller. It HELPS to implement all cross-cutting concerns or tracking request and response.

  • Dependency injection or inversion of control (IOC)

The spring framework is responsible for the creation, writing, configuring object and manage the entire lifecycle of these objects until they are completely DESTROYED. The container has the Dependency Injection (DI) responsible to manage the components present in an application.



Discussion

No Comment Found