Brush 14 interview questions: tell us about the design patterns used in your work?

image.png




Those most cheap time is settling time down, is to design mode, it will help improve the efficiency and quality of communication and design.


I was Li Fuchun, I prepare for the interview, today's question is:

work in what you use design patterns?


** Analysis: **
this problem is rather open, you can design patterns used in previous project experience, the selection of about two out of example to explain, talk about why you want to use design patterns, which brings advantages and inconveniences.

If it is not to be found, can be combined with jdk and spring, each pick one or two places concerned about two kinds of design patterns, we believe that the interviewer will be more satisfied.


** My answer: **


Design patterns are best practices precipitation programmer for many years in the design process, you can improve the quality of research between engineers, communication efficiency.

I use the X-Games access platforms in the template method pattern, scene: R & D game needs into different channels, each channel and user login interface to achieve top are not the same, and X as a gaming platform game access the different channels of service platforms need to ensure consistency of access to the game, and to eliminate differences in different channels.
Template Method of benefits:
  1. The flow of the game fixed access: have a login, prepaid access;
  2. Decoupling the agreement and implementation: each channel in accordance with the protocol access docking differences corresponding to the difference between the erase differences in the upper layer.
  3. Better scalability; you can easily add new channels;
  4. Access processing of the game can be more flexible;


I am in process optimization login code, using the Observer pattern. For example, you can use EventBus Spring event mechanism or guava provided;

before the login code is spaghetti, the line of code that handles a corresponding logic, for example, after the registration is completed, logging, notification integration services increased integration, inform statistical services increased Login frequency change Nikkatsu;

after using the viewer mode, made a successful login message, dealing with different logic operations in the listener. Simplifies the code, maintainability, extensibility is improved.

Finally, we can take inventory of classification and enumeration design patterns. The title Benpian FIG.


jdk design patterns used in inventory


Decorator: stream processing in java.io;

the builder pattern: Construction HTTP2 / client; a

singleton pattern: the Runtime class, Singleton mainly in the case of high concurrent need to lock bis subject, directly or gold For a single example of embodiment.

commonly used design patterns inventory spring


Factory mode: BeanFactory, ApplicationContext in object creation;

observer mode: publishing and notice of events

template pattern: the JdbcTemplate

AOP: a combination of agents, decorators, adapter mode

summary


Benpian answer in my experience design patterns examples of work, while extending the classification and enumeration of design patterns, if work can not think of what to use design patterns, can jdk, spring is used to design mode Case analysis about the use of design patterns as well as benefits.



image.png

The original is not easy, please indicate the source, let us complementarity and common progress, welcomed the multi-communication

Published 110 original articles · won praise 10 · views 20000 +

Guess you like

Origin blog.csdn.net/tian583391571/article/details/105118028