当前位置:网站首页>Programming principles
Programming principles
2022-06-13 09:43:00 【Wudi 98】
The design principle is to improve code maintainability , Help build flexibility 、 The cornerstone of a stable system . It mainly includes General design principles and S.O.L.I.D principle
General design principles It is a basic principle that we should adhere to and abide by in any development .
S.O.L.I.D principle It is more suitable for supporting object-oriented high-level languages , Some principles may not apply to current front-end development , But it is also beneficial for us to understand its ideas .
General design principles (Common Design Principles)
Keep It Simple and Stupid (KISS)
● The code should be easy to read and maintain .
● Don't over design a plan , The simplest solution to meet the needs is the best solution .
Don’t Repeat Yourself (DRY)
Don't repeat , Repetitive logic should be pulled apart for reuse , Repeated operations should be instrumented .
Tell, Don’t Ask
Also called “ Hollywood principle ”, This principle is about encapsulation and responsibility allocation . When interacting with other modules , It should tell the module what you want to do directly, not by judging the status of that module , Recall operation .
You Ain’t Gonna Need It (YAGNI)
Only the functions required by the application , Don't add functions you think you need .
TDD Is a kind of compliance YAGNI Development model .
Separation of Concerns (SoC)
Separate functions into independent function modules , These modules have their own independent behavior and data , To improve code reusability 、 Maintainability and testability .
S.O.L.I.D Design principles
Principle of single responsibility (Single Responsibility Principle - SRP)
This heel SoC Close , It specifies that each object should focus on only one function point 、 There is only one reason to change , Avoid Swiss Army knife objects .
Open and closed principle (Open-Closed Principle - OCP)
Open to expansion , Closed to modification .
Open to expansion , It means when there is a new demand or change , You can extend existing code , To adapt to the new situation . Closed to modification , It means that once the design is complete , You can do your job on your own , Add requirements without modifying their internal implementation .
Richter's principle of substitution (Liskov Substitution Principle - LSP)
Any subclass can replace the parent class without any modification .
Interface separation principle (Interface Segregation Principle - ISP)
Group similar interface methods to form a new interface , Avoid implementing a huge interface .
The principle of Dependence Inversion (Dependecy Inversion Principle - DIP)
The program depends on the abstract interface , Don't rely on concrete implementation , In short, it is interface oriented 、 Abstract oriented programming .
边栏推荐
- LeetCode 6096. Success logarithm of spells and potions (binary search)
- LeetCode 6095. Strong password checker II
- Instruction level parallelism (?)
- acwing 789. Range of numbers (dichotomy + suitable for understanding dichotomy boundary)
- 大O记法解释
- Protocol UART of schematic diagram
- 【 ssl2 ⁶⁶⁶⁶⁶⁶⁶⁶⁶⁶⁶⁶⁶⁶⁶⁶⁶⁶⁶83
- Attack and defense world PWN shell
- 说说MySQL索引机制
- MySQL事务隔离级别和MVCC
猜你喜欢
随机推荐
The rise of cloud computing enterprises and the shaking of Oracle database market dominance
Classes and objects -- object model and this pointer
(state compression dp+good) acwing 291 Mondrian's dream
Analysis and implementation of variable parameters in C language
(bfs+GOOD) acwing 845. Eight digit
Summary of string, vector and array learning
Amadahl's Law (a little thought)
GPIO of hardware schematic diagram
It was so simple to implement system call
MySQL monitoring tool PMM, let you go to a higher level (Part 2)
1-2 24:00 (20 points) [CSP certification true question]
LeetCode 322. Change
[pytorch environment installation]
LeetCode 5270. Minimum path cost in grid (dynamic programming)
一篇文章读懂:Spark运行模式
Classes and objects -- Inheritance
ThingsBoard教程(二一):使用消息类型和数据处理节点对数据处理后保存
Exercise 8-3 rotate the array to the right (20 points)
(dfs) acwing 842. Arrange numbers
Node-RED系列(二七):扩展节点之s7节点的使用说明


![[pytorch environment installation]](/img/00/78f6942ed3ff721675abb91504fb5c.png)





