The introduction

For example, Spring has a variety of Design patterns (BeanFactory’s factory pattern, Proxy patterns in AOP, adapter patterns, singleton beans, Spring’s event-driven model for observer patterns, and so on), but designing patterns in practice is in an awkward position. I don’t know what scene to use what design mode, but I feel I can use it but I’m afraid of unnecessary action.

In fact, with the growth of working age, reading the code of a good friend or a big man, you will find that your own code is a bit like Shit mountain, not only cannot adapt to the change of requirements, but also not so smooth in reading.

So how to change, design pattern is a good way. It can not only improve the readability, reusability and reliability of the code, but also be conducive to the stability and reliability of its own system. The docking of external systems, you will gradually find that the use of design pattern of system engineering, whether to meet the current needs, or adapt to the future needs are of great help.

From today I will continue to publish articles on design patterns, as well as the corresponding simple pseudocode to better understand design patterns, call your friends to learn together!

What are design patterns

Design pattern is actually a kind of programming thought that people sum up after a long period of experience. With the continuous evolution of software engineering, new design patterns are constantly put forward to meet different needs, but the principles of design patterns do not change. Based on the principle of design patterns, we can use existing design patterns, or combine, modify or redesign our own design patterns on the basis of existing design patterns according to the development requirements of products or projects.

Seven principles of design patterns

  • Single responsibility Principle

The single responsibility principle, also known as the single function principle, stipulates that a class has only one responsibility. If more than one responsibility is designed into a class, that class violates the single responsibility principle.

  • Open Close Principle

The open-close principle stipulates that the objects (classes, modules, functions, etc.) in the software are open to expansion and closed to modification. When the program needs to be expanded, the original code cannot be modified to achieve a hot-plug effect. In short, to make the program extensible, easy to maintain and upgrade.

  • Liskov Substitution Principle

Richter’s substitution principle is a supplement to the open and closed principle, stipulates that any place a parent class can appear, a subclass must appear. The key to implementing the open close principle is abstraction, parent and child classes, interfaces and implementation classes.

  • Dependence Inversion Principle

The dependency inversion principle states that programs need to rely on abstractions (abstract classes and interfaces in Java) rather than concrete implementations (implementation classes). In simple terms, it requires that the abstraction be converted into a single object, rather than programming the implementation, to decouple the user from the implementation module.

  • Interface Segregation Principle

The principle of interface isolation refers to the separation of interfaces by defining different functions on different interfaces. In this way, other classes do not rely on the interfaces they are not allowed to rely on, and the redundancy between interfaces can be reduced.

  • Composite Reuse Principle

The principle of aggregate reuse refers to the use and extension of classes by introducing existing objects into a new object. It is designed to use composition or aggregation rather than inheritance to extend the functionality of a class

  • Demeter Principle

Demeter’s law states that an object should interact with as few other objects as possible, i.e. an object should have as little knowledge or dependence on other objects as possible. The core idea is to reduce the coupling degree between modules.

Common Design patterns

conclusion

Here to introduce the concept of design mode and common design mode, to tell the truth, I am currently on the design mode is also a little knowledge, read the big guy source code and GitHub high start code, it seems to be a very lofty kind, like writing poetry, direct 🙇

For now, I plan to start with factory mode, and I will add links to each design mode in this article. I don’t know if you have any design mode you want to know, please reply below. We can learn and make progress together.

I’m Loger. Please give me a thumbs up

Skip links

Factory Pattern