The author | Liang Guizhao, slightly technology architects
-
What GOF design patterns are used in your project
-
Talk about the design concept of GOF’s 23 design modes
-
How do you implement design patterns in the Spring framework
If I were the interviewer and asked you these interview questions, think for a minute about how you would respond.
All right, let’s get down to business. Design pattern practices offer many enduring solutions and best practices. Here, GOF design patterns fall into three main categories: creation patterns, structural patterns, and behavior patterns. The create pattern is useful for creating object instances. Structural patterns act on the design structure of enterprise applications by dealing with the combination of classes or objects, thus reducing the complexity of applications and improving the reusability and performance of applications. The intent of a behavior pattern is an interaction between a group of objects to perform tasks that a single object cannot perform on its own. It describes class or object interactions and the assignment of responsibilities.
So, the core topic of this article is how Spring builds applications using a number of design patterns and good practices.
Factory method pattern
The Spring framework uses the factory pattern to implement the BeanFactory and ApplicationContext interfaces of the Spring container. The Spring container creates beans for Spring applications based on the factory pattern and manages the life cycle of each bean. BeanFactory and ApplicationContext are factory interfaces, and many implementation classes exist in Spring. The getBean() method is the factory method of the corresponding bean.
Abstract Factory pattern
The singleton pattern
Builder model
-
EmbeddedDatabaseBuilder
-
AuthenticationManagerBuilder
-
UriComponentsBuilder
-
BeanDefinitionBuilder
-
MockMvcWebClientBuilder
Adapter mode
-
JpaVendorAdapter
-
HibernateJpaVendorAdapter
-
HandlerInterceptorAdapter
-
MessageListenerAdapter
-
SpringContextResourceAdapter
-
ClassPreProcessorAgentAdapter
-
RequestMappingHandlerAdapter
-
AnnotationMethodHandlerAdapter
-
WebMvcConfigurerAdapter
The bridge model
-
ViewRendererServlet: This is a servlet bridge that primarily supports Portlet MVC
-
Bridge mode: Spring logging uses bridge mode
Decorator mode
-
Weave notifications into the Spring application. It uses the Decorator pattern’s CGLib proxy, which works by generating subclasses of the target class at run time.
-
BeanDefinitionDecorator: This enhances the definition of beans by using custom attributes.
-
WebSocketHandlerDecorator: it is used to enhance a WebSocketHandler additional behavior.
The appearance model
The proxy pattern
Chain of Responsibility model
Command mode
Interpreter mode
Iterator pattern
Observer model
At the end of the article think
Now that you know how the GOF design pattern is commonly implemented in the Spring framework, can you consider how the Spring framework implements the singleton pattern?
If you find this article helpful, please feel free to share it with more friends.
-
V V technology | IntelliJ IDEA in common plug-in, let the efficiency become a habit
-
Technology of dry goods | million level commodity data synchronization, real-time query results in seconds
-
Slightly recruitment | Q2 ReZhao post, recommend that 100% bonus
Follow the public account for more technical dry goods and recruitment information