software design principles

1. Single responsibility,
a class should have only one responsibility, otherwise coupling.

2. Open-closed principle,
extensible and unmodifiable. For the part that needs to be modified, use abstract isolation.

3. Dependency inversion principle
The high layer (caller) should not depend on the low layer (callee), both need to depend on abstraction;
abstraction should not depend on details, details should depend on abstraction (interface-oriented)
Example: business class calls Sqlserver data Classes and business logic are perfectly encapsulated, and then there is a new project at this time, which needs to be used mysql, and the mysql data class needs to be rewritten at this time, but the business class is completely reusable. Then in the new project, after the business class is transplanted, all places that call the SQL data class need to be changed to call the mysql data class. If the business class in the old project calls the interface, then the MySQL data class in the new project only needs to inherit the interface, and then the business code can be left completely unchanged.

4. The Liskov substitution principle
changes the behavior of calling the parent class to calling the child class without any change. That is, the subclass must be able to completely replace the parent class.
It is precisely because the subclass can completely replace the parent class that the module calling the parent class can achieve infinite expansion.
Example: If the penguin inherits the bird, it violates the Liskov substitution principle, because the bird can fly, but the penguin can't.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324892940&siteId=291194637