Common design principles -SOLID, you can click on the link to view.
Next, learn about KISS, YANGI, DRY, Demeter’s Law and other design principles.
KISS principle
There are three ways to describe it
Keep It Simple and Stupid.
Keep It Short and Simple.
Keep It Simple and Straightforward.
Keep it simple.
YANGI principle
You Ain’t Gonna Need It. You won’t need it. In fact, the core idea of this rule is: Don’t overdesign.
The YAGNI principle is not the same thing as the KISS principle: the KISS principle is about the “how” question (keep it simple), while the YAGNI principle is about the “do or not do” question (don’t do what you don’t need right now).
DRY principle
Its English description is: Don’t Repeat Yourself. Don’t repeat yourself. When applied to programming, it can be interpreted as: Don’t write repetitive code.
Demeter’s rule (LoD)
Law of Demeter, LoD is more intuitive called The Least Knowledge Principle, English translation: The Least Knowledge Principle.
Each unit should have only limited knowledge about other units: only units “closely” related to the current unit. Or: Each unit should only talk to its friends; Don ‘t talk to strangers.
Translated into Chinese:
Each module should have limited knowledge of units: only units “closely” related to the current unit. Or, each module only “talks” to its own friends, not strangers.
Using this principle can help us achieve “highly cohesive, loosely coupled” code.
Why do I say that the KISS and YAGNI principles seem so simple, but they are often used incorrectly? Does duplicate code necessarily violate DRY? How can you improve your code’s reusability? How to use Demeter’s Law (LOD) to achieve “high cohesion, loose coupling”?