JDK, Spring and Mybatis used to design pattern

A, JDK in the design pattern
(1) Structural model
1. Adapter Mode
java.util.Arrays asList # ()
the java.io.InputStreamReader (the InputStream)
java.io.OutputStreamWriter (the OutputStream)
java.xml.bind.annotation. Mashal # adapters.xmlAdapter ()
java.xml.bind.annotation.adapters.xmlAdapter Mashal # ()
2. bridge mode (abstract and concrete to achieve decoupling abstraction, so that can abstract and abstract may be embodied independently change.)
the JDBC
3. the combination mode (the client to look at the combination of the processing object and the individual objects are equal, in other words, a type of method also accepts as its own parameter type.)
java.util.List # the addAll (Collection)
java.util.Set the addAll # (Collection)
java.util.Map the addAll # (the Map)
. 4 decorator pattern
java.io.BufferedInputStream (the InputStream)
5. The mode facade
the java.lang .Class
6. The Flyweight (use cache to reduce access time for small objects)
java.lang.Integer # valueOf (int)
# ValueOf Java.lang.Bollean (Boolean)
java.lang.Byte # valueOf (byte)
java.lang.Character # valueOf (char)
7. The proxy mode
the java.lang.reflect.Proxy
(2) creating mode
8. abstract factory mode
java.sql.DriverManger # getConnection ()
java.sql.Connection the createStatement # ()
java.text.NumberFormat # getInstance ()
java.util.Calender # getInstance ()
9. builder mode
java.lang.StringBuilder # apend ( )
java.lang.StringBuffer the append # ()
java.sql.PreparedStatement
10. The method of plant
Java.lang.Proxy # 'newProxyInstance ()
java.lang.Object # toString ()
java.lang.Class the newInstance # ()
the java.lang. # forName Class ()
Java.lang.Bollean # valueOf (String)
11. A prototype model (instance of the class can be generated such that a copy of itself.)
Java.lang.Object clone # ()
the java.lang.Cloneable
12. The singleton
java.langRuntime getRuntime # ()
the bean in Spring
13. behavior (next object by forwarding the request from one object to the chain in a manner to decouple the object until the request processing is finished.)
java.util.logging.Logger # log ()
the javax.servlet.Filter the doFilter # ( )
14. the command mode (command packaged in a subject, so it can be stored, transmitted to the process, like any other object and returns.)
the java.lang.Runnable ()
15. a interpretation mode
Java.text.Format
16. the iterative mode
Java.uil.Iterator
17. a mediator mode (by using an intermediate object to the message distribution and reduce direct dependency between the classes.)
java.util.Timer
java.util.concurrent.Executor # Execute ( )
java.util.concurrent.ExecutorService # the Submit ()
java.lang.reflect.Method # the Invoke ()
18. the null object mode (which allows you to deal with abstract empty object.)
# emptyList java.util.Collections ()
java.util.Collections # emptyMap ()
java.util.Collections # emptySet ()
19. A viewer mode
java.util.EventListener
java.servlet.http.HttpSessionBindingListener
java.servlet.http. HttpSessionAttributeListener
20. the state mode (allows you to easily change the object at run time based on the internal state behavior.)
Java.uil.Iterator
Java.faces.lifecycle.LifeCyele # the Execute ()
21. the strategy mode (use this model to a set of algorithms packaged into a series of objects)
java.util.Comparator comoare # ()
java.servlet.http.HttpServlet
java.servlet.Filter the doFilter # ()
22. a method of pattern template (so subclasses can override a portion of a method, rather than the entire heavy write, you can control subclasses need to override those operations.)
java.util.Collections # the Sort ()
java.io.InoutStream # the Read ()
java.util.AbstractList # indexOf ()
23. visitor mode (to provide a convenient manner to maintain the operation such that a set of objects that you do not change under the premise of the operation object can be modified or extended object's behavior..)

HTTPS: //mp.weixin.qq .com / s / QwlkU1T4RQaRqgs9uI3cPg


two design patterns used by Spring
1. simple factory pattern
spring in the BeanFactory
2. factory methods
commonly used by the new application directly create a new object, the object in order to create and use the phase separation, using the factory pattern, that is, the application will create and initialize the object's responsibilities to the factory object.
Application has its own factory object to create the bean. If the application is subject to the Spring own factory management, the management of Spring is not common bean, but the factory Bean.
Spring FactoryBean the factory method is a typical pattern.
Example 3. Single mode
to ensure that only one instance of a class, and it provides access to a global access point.
Default next Spring bean are singleton, by singleton = "true | false" or to specify scope = "?."
4. proxy mode
in Aop in the Spring, the Advice used (notification) to enhance the functionality of the proxy class. Spring AOP to achieve this principle on the use of proxy functionality mode (1, JDK dynamic proxy.
2, CGLib byte code generation techniques agent.) Based on the method of reinforcing section level, i.e., the proxy class is generated proxy class, and before the proxy class method is provided interceptor,
it enhances the functionality of the proxy method by performing block content high regard, aspect-oriented programming implementation.
5. observer pattern
Definition of the dependencies between the subject an-many, when a state of the object changes, all objects that depend on it have been notified and updated automatically.
spring in Observer mode is commonly used in place of the realization of listener. As ApplicationListener.
6. The strategy pattern
defines a series of algorithms, encapsulate them one by one, and makes them interchangeable. This mode makes the algorithm can be varied independently of the clients that use it.
Strategy pattern used in spring when the instance of the object
7. Template Method
spring in JdbcTemplate.
8. Packing Mode
Spring used in the packaging mode in two forms in the class name: one is the class name contained Wrapper, another is the class name contained Decorator. Basically to an object dynamically add some additional responsibilities.
9. The adapter mode
implementations: the adapter HandlerAdatper SpringMVC.
The principle: HandlerAdatper perform different Handler Handler according to the rules.
Implementation:
the DispatcherServlet The return handler HandlerMapping, initiates a request to HandlerAdatper, processing Handler. HandlerAdapter find the rules and allowed to perform the corresponding Handler,
Handler will return to a ModelAndView HandlerAdapter after the implementation, and finally return to a ModelAndView DispatchServelet by the HandlerAdapter.
Achieve significance:
HandlerAdatper Handler be easily extended so that, only need to add a new Handler and to a corresponding HandlerAdapter. Spring thus defines an adaptation interface, each Controller so that
there is a corresponding adapter implementation class, instead of the controller adapter so that the respective method. So that when the expansion Controller, only need to add an adapter class to complete the expansion of the SpringMVC.

Third, the design patterns used in mybatis

1.Builder模式,例如SqlSessionFactoryBuilder、XMLConfigBuilder、XMLMapperBuilder、XMLStatementBuilder、CacheBuilder;

2. The factory pattern, e.g. SqlSessionFactory, ObjectFactory, MapperProxyFactory;

Example 3. Single mode, e.g. ErrorContext and LogFactory;

4. The core proxy mode, Mybatis implemented, such MapperProxy, ConnectionLogger, with a dynamic proxy jdk; executor.loader package also used to achieve the effect javassist cglib or delay loading;

The combined mode, e.g. SqlNode and each subclass ChooseSqlNode the like;

6. The method of template pattern, e.g. BaseExecutor and SimpleExecutor, as well as all subclasses and BaseTypeHandler e.g. IntegerTypeHandler;

7. The adapter mode, for example, and its adaptation jdbc, log4j other logging framework of Log Mybatis interface;

8. decorator pattern, e.g. Cache package medium realize the respective sub-packets cache.decorators decorator;

9. The iterative mode, such as iterative mode PropertyTokenizer;

Guess you like

Origin www.cnblogs.com/heqiyoujing/p/11210634.html