Java---Design Patterns---Basic Principles

1. Interface-oriented programming

    1) This is the generally accepted first principle in Java programming.

    2) An important function of the interface: encapsulation and isolation.

    3) An interface is the appearance of a function block or encapsulation block


2. Prefer object composition over class inheritance

3. Layering ( the most typical three-layer structure: presentation layer --> logic layer --> data layer )


4. Basic principles of interaction between layers

   1) The presentation layer calls the logic layer, and the logic layer calls the data layer, not the other way around.

   2) The interaction between layers should also be called through the interface to ensure that the implementation of each layer changes independently.

5. Open-Closed Principle ( OC Principle )

    Simply put, it is open to new additions and closed to modifications. And you should try to change the behavior of the module without modifying the source code of the module.

6. Dependency Inversion Principle

    The principle is to rely on abstractions rather than concrete implementations.

7. Interface isolation principle

    The principle is not to use a common interface, but to use different interfaces for different users. ( Try to write dedicated interfaces as much as possible, and use less general interfaces )

8. The principle of substitution

    The principle is that subclasses should be able to replace the superclass and appear wherever the superclass can. In other words, subclasses should try not to override methods of superclasses.


    









Guess you like

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