Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the design pattern interview questions in the front end of web

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

In this issue, the editor will bring you the interview questions about the design patterns in the front end of web. The article is rich in content and analyzes and describes for you from a professional point of view. I hope you can get something after reading this article.

A brief introduction to the seven principles of design pattern

Open and closed principle: open to extension, closed to modification. When the program needs to be expanded, the original code can not be modified artificially to achieve a hot-swappable effect.

Single responsibility principle: a class, interface, or method is responsible for only one responsibility, which reduces code complexity and reduces the risk of code changes.

Dependency inversion principle: programming for interfaces depends on abstract classes or interfaces rather than on concrete implementation classes.

Interface isolation principle: different functions are defined in different interfaces to achieve interface isolation.

Richter substitution principle: subclasses can appear wherever a base class can appear.

Demeter principle: each module should know and rely on other modules as little as possible to reduce code coupling.

Synthetic reuse principle: try to use has-a / contains-an instead of is-a to achieve the purpose of software reuse.

A brief introduction to the classification of design patterns

Creative mode: hides the creation logic while creating the object, and instantiates the object directly without using new. The pattern includes factory method pattern, abstract factory pattern, singleton pattern, builder pattern and prototype pattern.

Structural pattern: creating objects with complex structures through inheritance and references between classes and interfaces. The pattern includes adapter mode, decorator mode, proxy mode, appearance mode, bridge mode, combination mode, and sharing meta-mode.

Behavioral model: different behaviors are realized through different ways of communication between classes. The pattern includes policy pattern, template method pattern, observer pattern, iterative sub-pattern, responsibility chain pattern, command mode, memo mode, state mode, visitor mode, intermediary mode and interpreter pattern.

A brief introduction to the simple factory model

The simple factory pattern refers to the creation of an instance by a factory object, which is suitable for situations where the factory class is responsible for creating fewer objects. Example: BeanFactory in Spring uses a simple factory pattern to produce Bean objects.

A brief introduction to the factory model

The factory method pattern refers to defining an interface that creates an object, letting the implementation class of the interface decide which object to create, and deferring class instantiation to subclasses. Example: the getObject method of Spring's FactoryBean interface is also a factory method.

A brief introduction of Abstract Factory pattern

The abstract factory pattern provides an interface for creating a series of related or interdependent objects without specifying their concrete classes. Example: java.sql.Connection interface.

A brief introduction to the singleton model

There is only one instance of a singleton class in any case.

The realization of hungry Han style

Public class Singleton {private Singleton () {} private static Singleton instance = new Singleton (); public static Singleton getInstance () {return instance;}}

Lazy realization

Public class Singleton {private DoubleCheckSingleton () {} private volatile static Singleton instance; public static Singleton getInstance () {if (instance = = null) {synchronized (Singleton.class) {if (instance = = null) {instance = new Singleton ();} return instance }} briefly describe the agent mode

The proxy pattern provides a proxy for other objects to control access to that object. The advantage is that it can enhance the function of the target object, reduce the code coupling and have good expansibility. The disadvantage is that adding proxy objects between the client and the target object will slow down the request processing speed and increase the complexity of the system.

Static proxy: the bytecode file of the proxy class already exists before the program runs, and the relationship between the proxy class and the delegate class is determined before the program runs.

Dynamic proxy: the agent is generated dynamically during the run of the program, so there is no bytecode file for the agent class. The relationship between the proxy class and the delegate class is determined when the program is running.

A brief introduction of Adapter Mod

The adapter pattern converts one interface into another that the customer wants, so that classes with incompatible interfaces can work together.

A brief introduction of template Mod

The template pattern defines the skeleton of an operational algorithm and delays some steps to a subclass, which is suitable for extracting repeated code from a subclass to a common parent class. The fixed part can be encapsulated and the variable part can be extended. But each different implementation requires a subclass maintenance, which increases the number of classes.

Brief introduction of decorator mode

Decorator pattern can dynamically add some additional properties or behavior to the object, that is, when you need to modify the original function, but do not want to modify the original code directly, design a Decorator to cover the original code.

A brief introduction to the Observer Model

The observer pattern represents a dependency between objects. When the state of an object changes, all objects that depend on it are notified and updated automatically.

These are the interview questions of the design patterns in the front end of web shared by the editor. If you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report