In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article introduces the relevant knowledge of "how to understand design patterns in javascript". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
In javascript, design patterns are solutions to some specific problems in software development, which can also be understood as some ideas to solve problems. Design patterns can help us enhance the reusability, expandability, maintainability and flexibility of the code.
The operating environment of this tutorial: windows7 system, javascript1.8.5 version, Dell G3 computer.
What is a design pattern?
Design pattern (Design pattern) is to solve some specific problems in software development and some solutions can also be understood as some ideas to solve the problem. Design patterns can help us enhance the reusability, expandability, maintainability and flexibility of the code. The ultimate goal of using design patterns is to achieve high cohesion and low coupling of the code.
What is high cohesion and low coupling?
Take a real-life example, such as a company, where each department generally performs its own duties and does not interfere with each other. When each department needs to communicate, it is docked through a special person in charge. It is the same in the software. A function module only pays attention to one function, and a module had better realize only one function. This is the so-called cohesion, and the interaction between modules and systems is inevitable, but we should try our best to reduce the situation that a single module cannot be used independently or can not be transplanted because of the interaction. as much as possible, separate interfaces are provided for external operations, which is called low coupling.
Design principle
Single responsibility principle (SRP)
An object or method does only one thing. If a method takes on too much responsibility, the more likely it is that the method needs to be rewritten during the change of requirements.
Objects or methods should be divided into smaller granularities
Principle of least knowledge (LKP)
A software entity should interact with other entities as little as possible
Interaction between objects should be minimized. If two objects do not have to communicate directly with each other, then the two objects do not have direct contact with each other and can be handed over to a third party for processing
Open-closed principle (OCP)
Software entities (classes, modules, functions, etc.) should be extensible, but not modifiable
When you need to change the function of a program or add new functions to the program, you can use the way of adding code to avoid changing the source code of the program as far as possible to prevent the stability of the original system from being affected.
Fifteen common design patterns in JavaScript
1. Singleton mode
2. Strategy mode
3. Agent mode
4. Iterator mode
5. Publish-subscribe model
6. Command mode
7. Combination mode
8. Template method mode
9. Enjoy meta-mode
10. Duty chain model
11. Intermediary model
12. Decorator mode
13. State mode
14. Adapter mode
15. Appearance mode
This is the end of "how to understand Design patterns in javascript". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.