Design Patterns used in Spring Framework
Following are the design patterns used in Spring Framework
MVC Design Pattern is a software design that separates the following components of a system or subsystem:
|Proxy Pattern||Spring uses either JDK proxies (preferred wheneven the proxied target implements at least one interface) or CGLIB proxies (if the target object does not implement any interfaces) to create the proxy for a given target bean. Unless configured to do otherwise, Spring AOP performs run-time weaving Suppose we want to log every method entry and exit. This can be achieved by writing log statements in every method at the start and end. But this will require lot of code work. There are various such tasks like Security which need to be applied across all methods or classes. These are known as cross cutting concerns.AOP addresses the problem of cross-cutting concerns, which would be any kind of code that is repeated in different methods and cannot normally be completely refactored into its own module, like with logging or verification.|
|Factory Pattern||This patterns is used by spring to load beans using BeanFactory and Application context.|
|Singleton Pattern||Beans defined in spring config files are singletons by default. A singleton bean in Spring and the singleton pattern are quite different. Singleton pattern says that one and only one instance of a particular class will ever be created per classloader. The scope of a Spring singleton is described as "per container per bean". It is the scope of bean definition to a single object instance per Spring IoC container. The default scope in Spring is Singleton.|
|Template method Pattern||Template method design pattern is to define an algorithm as skeleton of operations and leave the details to be implemented by the child classes. The overall structure and sequence of the algorithm is preserved by the parent class. These are used extensively to deal with boilerplate repeated code|
Front Controller is a controller pattern which provides a centralized controller for managing requests.
Each client request must go through and be processed by the Front Controller first, no exceptions.
All incoming data is delegated to front controller first. Useful for when your application has multiple
entry points which you want to centralize through a single point for standardized processing.
Spring implements this design pattern using DispatcherServlet, to dispatch incoming requests to the correct controllers.
|View Helper Pattern||
View Helper arranges view components for the user and delegates processing to other business components so the view component doesn't have to
contain any processing logic other than logic to present views.
Spring makes use of custom JSP tags etc to separate code from presentation in views.
The Prototype pattern is known as a creational pattern,as it is used to construct objects such that they can be decoupled from their implementing systems.
It creates objects based on a template of an exsiting object through cloning.
Dependency Injection/Inversion of Control design pattern allows us to remove the hard-coded dependencies and make our application loosely coupled, extendable and maintainable.
We can implement dependency injection in java to move the dependency resolution from compile-time to runtime.