当前位置:网站首页>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 .
边栏推荐
- acwing 789. Range of numbers (dichotomy + suitable for understanding dichotomy boundary)
- 信息文档管理与配置管理
- acwing 786. Number k
- (bfs) acwing 847. Hierarchy of points in the graph
- 隐私计算FATE-核心概念与单机部署
- [51nod P3210] binary statistics
- ThingsBoard教程(二十):使用规则链过滤遥测数据
- 递归想法和实现介绍,消除递归
- GPIO of hardware schematic diagram
- Class template
猜你喜欢
[51nod P3210] binary statistics
(tree DP) acwing 285 A dance without a boss
MySQL利用E-R模型的数据库概念设计
[ssl1271] sort I [heap]
Node-RED系列(二五):集成高德地图并实现3d地图和轨迹回放
Tree and binary tree: operation and storage structure of tree
Acwing785. quick sort (sort+ quick sort + merge sort)
Trees and binary trees: Construction of binary trees
信息文档管理与配置管理
Leetcode (question 15) - sum of three numbers
随机推荐
英国出台粮食安全计划抵御粮食供应危机
Tree and binary tree: operation and storage structure of tree
VDD,DVDD,AVDD,VCC,AFVDD,DOVDD,IOVDD
Exercise 8-3 rotate the array to the right (20 points)
六月集训(第13天) —— 双向链表
VGA常用分辨率及计算方法
(dfs) acwing 842. Arrange numbers
Class and object -- friend
Learning makefile with me
Exercise 7-10 finding specified characters (15 points)
Node-RED系列(二五):集成高德地图并实现3d地图和轨迹回放
Classes and objects -- object model and this pointer
【动态规划】入门篇
UNIX Environment advanced programming --8- process control ---8.5 function exit-8.6 function wait and waitpid
Calculate the number of days between two times (supports cross month and cross year)
matlab轮毂电机分析模糊pid控制垂向振动分析
LeetCode 5289. Fair distribution of cookies (DFS)
Overloading of typical operators
[51nod p3058] Xiao ming'ai set [set]
(state compression dp+ binary) acwing 91 Shortest Hamilton path