当前位置:网站首页>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 (question 15) - sum of three numbers
- 六月集训(第13天) —— 双向链表
- LeetCode 6098. Count the number of subarrays whose score is less than K (prefix and + binary search)
- A static variable is associated with a class and can be used as long as the class is in memory (the variable does not exist as long as your application terminates). (heap body, stack reference)
- Musk's "meta universe" dream
- VDD,DVDD,AVDD,VCC,AFVDD,DOVDD,IOVDD
- [51nod 2493] sum of binary distances [bit operation]
- Node-RED系列(二四):在Node-RED中使用mysql节点实现数据库的增删改查
- MySQL事务隔离级别和MVCC
- LeetCode 322. Change
猜你喜欢

Jenkins access openldap user authentication

The rise of cloud computing enterprises and the shaking of Oracle database market dominance

二叉树简介

云计算企业崛起 甲骨文数据库市场主导地位动摇

(dfs+ tree DP) acwing 846 Center of gravity of tree

Node-RED系列(二四):在Node-RED中使用mysql节点实现数据库的增删改查

Knowledge points of silicon steel sheet

(dfs) acwing 842. Arrange numbers
![[51nod 2493] sum of binary distances [bit operation]](/img/e9/8a8393f41cac7c323712c34f4d3e01.jpg)
[51nod 2493] sum of binary distances [bit operation]

matlab轮毂电机分析模糊pid控制垂向振动分析
随机推荐
Britain introduces food security plan to resist food supply crisis
Pxxx local socket communication
Biden: hope to sign the bipartisan gun safety reform bill as soon as possible
[Luogu p1403] Research on divisor
List list
matlab轮毂电机分析模糊pid控制垂向振动分析
Class template
(bfs+GOOD) acwing 845. Eight digit
递归想法和实现介绍,消除递归
多线程 从UE4的无锁队列开始 (线程安全)
LeetCode 5270. Minimum path cost in grid (dynamic programming)
LeetCode 6095. Strong password checker II
[pytorch environment installation]
acwing 789. Range of numbers (dichotomy + suitable for understanding dichotomy boundary)
Jenkins集成Ldap,Ldap配置错误导致jenkins用户登录失败问题解决
23. Lottery
I have summarized the knowledge points of JS [intermediate and advanced] for you
Tree and binary tree: operation and storage structure of tree
单例模式的实现
Memory management -- Viewing memory space from the perspective of executing programs and processes