Design pattern interview questions

Tell me what design patterns you know

Creational pattern: singleton pattern, factory pattern, builder pattern
Structural model: adapter pattern, bridge pattern, decoration pattern, proxy pattern
Behavioral pattern: template method pattern, observer pattern, strategy pattern

Which design patterns are used in JDK

Almost every design pattern has been used in the source code of JDK. Here are some common ones:
(1) Abstract factory pattern
javax.xml.parsers.DocumentBuilderFactory#newInstance()
javax.xml.transform.TransformerFactory#newInstance()
( 2) Builder mode
java.lang.StringBuilder#append()
java.lang.StringBuilder#append()
(3) Prototype mode
java.lang.Object#clone()
(4) Adapter mode
java.util.Arrays#asList( )
java.util.Collections#list()
(5) Flyweight mode
java.lang.Integer#valueOf(int)

What design patterns are used in Spring

(1) Singleton design pattern: Beans in Spring are all singletons by default.
(2) Proxy design pattern: the implementation function of Spring AOP.
(3) Factory design mode: Spring uses the factory mode to create Bean objects through BeanFactory and ApplicationContext;
(4) Template method mode: in Spring, jdbcTemplate, hibernateTemplate and other classes that end with Template for database operations use the template mode.
(5) Decorator design mode: The project needs to connect to multiple databases, and different customers need to access different databases in each visit. This mode can dynamically switch different data sources according to customer needs.
(6) Observer mode: The Spring event-driven mode is a classic application of the observer mode.
(7) Adapter mode: Spring AOP's enhancement or advice (Advice) uses the adapter mode, and SoringMVC also uses the adapter mode to adapt to the Controller.

おすすめ

転載: blog.csdn.net/weixin_49131718/article/details/131664668