Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the common design principles in programming development

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article will explain in detail what are the common design principles in programming development. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.

Common design principles

Principle of simplicity (KISS)

The goal of the KISS principle is to keep the code simple but not too simple, so as to avoid introducing any unnecessary but complexity.

Don't repeat yourself (DRY)

The BRY principle, however, aims to avoid repeating any part of the system by pulling out the common parts and placing them in a separate place. Of course, it is not only the code that avoids repetition, but also the business logic.

Tell without asking (Tell,Don't Ask)

This principle requires that you tell the object what action you want them to perform, rather than ask questions about the state of the object and then decide for yourself what action you want to perform. This helps to match responsibilities and avoid tight coupling between classes.

You don't need it (YAGNI)

This principle means that you only need to include the functionality that your application must have, and don't try to add any other features that you think you might need.

Separate concerns (SoC)

The process of SoC decomposes the software into several different functions, each of which encapsulates unique behaviors and data that can be used by other classes. Typically, a concern represents a function or behavior of a class. The practice of dividing the program into several independent responsibilities significantly improves the reuse, maintainability and testability of the code.

Design principles of S.O.L.I.D

Single responsibility principle (SRP)

SRP is highly consistent with the principle of separation of concerns. It requires that each object should have one and only one responsibility focus, that is, there is only one cause for class change.

Open and closed principle (OCP)

This principle requires that the class should be open for extensions and closed for modifications, so that new functionality should be added to the class without changing the internal behavior of the class, and prevent the class from being destroyed, causing unnecessary errors or bug.

Richter substitution principle (LSP)

Any parent class should be able to be replaced by a subclass and keep its behavior unchanged. The change principle is consistent with the OCP principle to ensure that the inherited class does not affect the behavior of the parent class.

Interface separation principle (ISP)

The ISP principle focuses on dividing interface methods into groups of responsibilities and assigning different interfaces to these groups. Avoid implementing a large and unused interface on the client side.

Dependency inversion principle (DIP)

The purpose of the DIP principle is to isolate the classes you write from the concrete implementation, making them dependent on abstractions or interfaces. It promotes interface-oriented programming, which ensures that the code is not tightly coupled to an implementation, thereby increasing the flexibility of the evil system.

Dependency injection (DI) and inversion of Control (SoC) principles

DI, SoC and DIP are closely linked. DI provides lower-level or subordinate classes through constructors, methods, or properties. In conjunction with the DI principle, these subordinate classes can be inverted into interfaces or abstract classes, thus forming a low-coupling system with high testability and easy modification.

This is the end of this article on "what are the common design principles in programming development". I hope the above content can be of some help to you, so that you can learn more knowledge. If you think the article is good, please share it for more people to see.

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: 298

*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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report