当前位置:网站首页>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 .
边栏推荐
猜你喜欢

Node-RED系列(二五):集成高德地图并实现3d地图和轨迹回放
![[51nod p2527] or and sum [bit operation]](/img/50/75ee9ee40ef0ca9b99e6900018b61a.jpg)
[51nod p2527] or and sum [bit operation]

简述请求过程

【20220526】UE5.0.2 release d11782b

Exercise 7-7 string replacement (15 points)

Learning makefile with me

Tree and binary tree: basic operation and implementation of binary tree

(bfs) acwing 847. Hierarchy of points in the graph

Jenkins接入Openldap用戶認證

(dfs+ pruning + checkerboard problem +dood) acwing 843 N-queen problem
随机推荐
Leetcode points to offer 30 Stack containing min function
Simple use of spiel expressions
隐私计算FATE-核心概念与单机部署
VDD,DVDD,AVDD,VCC,AFVDD,DOVDD,IOVDD
Classes and objects -- polymorphic
UNIX Environment advanced programming --8- process control ---8.5 function exit-8.6 function wait and waitpid
VDD,DVDD,AVDD,VCC,AFVDD,DOVDD,IOVDD
go-zero微服务实战系列(三、API定义和表结构设计)
[51nod p2673] shortest path [heap optimization Dijk]
Remember! Don't be too confident in writing code! Be sure to write some key log info output, or the problem will not be located.
[most comprehensive and detailed explanation] detailed explanation of knapsack problem
It was so simple to implement system call
Classes and objects -- Inheritance
LeetCode 2016. Maximum difference between incremental elements
Queue and stack
Acwing785. quick sort (sort+ quick sort + merge sort)
Instruction level parallelism (?)
(dijkstra+ shortest path + edge traversal 0 (m)) acwing 850 Dijkstra finding the shortest path II
Execution order of subclass and parent constructor
Summary of random number learning