Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What design patterns are used in Spring framework? [closed]

What design patterns are used in Spring framework?

like image 709
Isabel Jinson Avatar asked Apr 16 '09 10:04

Isabel Jinson


People also ask

Which design pattern is used in Spring IOC?

Singleton Pattern In the spring framework, IOC manages a lot of beans. As a default, a bean is created which has a singleton scope. Singleton means “A class of which only a single instance can exit”.

Does Spring use prototype design pattern?

Spring does not use the Prototype Pattern, it uses reflection.

What pattern does Spring MVC use?

Spring MVC Framework follows the Model-View-Controller design pattern. It is used to develop web applications. It works around DispatcherServlet. DispatcherServlet handles all the HTTP requests and responses.

Which of the following design pattern in Spring provides DispatcherServlet?

Front Controller Pattern Spring provides DispatcherServlet to ensure an incoming request gets dispatched to your controllers.


2 Answers

There are loads of different design patterns used, but there are a few obvious ones:

  • Proxy - used heavily in AOP, and remoting.

  • Singleton - beans defined in spring config files are singletons by default.

  • Template method - used extensively to deal with boilerplate repeated code (such as closing connections cleanly, etc..). For example JdbcTemplate, JmsTemplate, JpaTemplate.


Update following comments: For MVC, you might want to read the MVC Reference

Some obvious patterns in use in MVC:

  • Model View Controller :-) . The advantage with Spring MVC is that your controllers are POJOs as opposed to being servlets. This makes for easier testing of controllers. One thing to note is that the controller is only required to return a logical view name, and the view selection is left to a separate ViewResolver. This makes it easier to reuse controllers for different view technologies.

  • Front Controller. Spring provides DispatcherServlet to ensure an incoming request gets dispatched to your controllers.

  • View Helper - Spring has a number of custom JSP tags, and velocity macros, to assist in separating code from presentation in views.

like image 185
toolkit Avatar answered Oct 01 '22 00:10

toolkit


And of course dependency injection, or IoC (inversion of control), which is central to the whole BeanFactory/ApplicationContext stuff.

like image 35
Chochos Avatar answered Oct 01 '22 00:10

Chochos