[Design Mode] inherited adaptation mode

problem:

  Have encountered a problem of design patterns: spring inside HandlerInterceptor there is implementation class is HandlerInterceptorAdaptor, name of the class is ending adaptor, but the interface is actually HandlerInterceptor do a few basic implementation, why not be called AbstractHandlerInterceptor? HandlerInterceptorAdaptor The name obviously is to represent the adapter mode, but actually are not, the end of spring I found a lot of this with adapter

analysis:

  It is not only Spring, and many open source frameworks like Netty has a lot Adaptor the end of the class, we can usually find is that there are Adaptor class method provides a simple implementation of all of the default, and abstract classes that begin with Abstract inevitable open out the abstract methods;

  Then the Adapter class is made abstract class, but it offers all realize, there is no open interface out, but they can not be instantiated, then how to use it? So the user is bound to inherit it, but also to achieve the interception but also you need to override the method, which requires implementers of the superstructure interceptors are well aware of, but it is possible to achieve classes who do not want it implemented and any duties assigned to "interceptor" this type of intrusive, may realize the eyes of those who do is a privilege validation class, do not want the logical frameworks, but have to be understood and invocation framework, how to resolve this contradiction it? Adapting this idea came, I adapted by adapting the surface of the frame, but I was able to completely out of the frame, because even if overridden method to remove my class named meaning is also unaffected.

  So it may look out, by the end of the Adapter is for designers who want to butt executives a better understanding, a model that performs its own adapter, which can make class methods inherited from descriptive naming is consistent, is a neat Code the mechanism; why clean code? If the in-depth understanding of the "reconstruction" and "code clean way," the friend estimated it was clear how important it is named after a class; artistic code, is there from the beginning of Sense;

in conclusion:

  Clean code inherited adaptation mode

Guess you like

Origin www.cnblogs.com/iCanhua/p/10941493.html