JAVA Design Patterns ---- Overview

In the JAVA development process, you will always use design patterns intentionally or unintentionally. Usually high-quality projects are bound to lack the use of design patterns.

In total, there are 23 design patterns in JAVA. They respectively solve many problems in daily development such as code conciseness, code reuse, code readability and so on.

Classification of design patterns:  

There are five types of creational patterns: singleton pattern, factory method pattern, abstract factory pattern, builder pattern, and prototype pattern.    

There are seven structural modes: adapter mode, decoration mode, proxy mode, appearance mode, bridge mode, composition mode, and flyweight mode.    

There are eleven behavioral patterns: strategy pattern, template method pattern, observer pattern, iteration sub pattern, responsibility chain pattern, command pattern, memorandum pattern, state pattern, visitor pattern, mediator pattern, and interpreter pattern.

Six principles of design patterns  

Open Close Principle  

The open-closed principle means that it is open for extension and closed for modification. When the program needs to be expanded, the original code cannot be modified to achieve a hot-plug effect. So one sentence summary is: in order to make the program expandable, easy to maintain and upgrade. To achieve this effect, we need to use interfaces and abstract classes, which we will mention in the specific design later. 

 Liskov Substitution Principle 

Liskov Substitution Principle (LSP) is one of the basic principles of object-oriented design. The Liskov Substitution Principle states that wherever a base class can appear, a subclass must appear. LSP is the cornerstone of inheritance and reuse. Only when the derived class can replace the base class and the function of the software unit is not affected, the base class can be truly reused, and the derived class can also add new behaviors based on the base class. . The Liskov substitution principle is a complement to the "open-closed" principle. A key step in implementing the "open-closed" principle is abstraction. The inheritance relationship between the base class and the subclass is the concrete realization of abstraction, so the Liskov substitution principle is the specification of the concrete steps to realize abstraction. ——From Baidu

Dependence Inversion Principle  

This is the basis of the open-closed principle, the specific content: true programming to the interface, relying on abstraction rather than concreteness.

Interface Segregation Principle  

What this principle means is that it is better to use multiple isolated interfaces than to use a single interface. It also means reducing the degree of coupling between classes. From here, we can see that a design pattern is actually a software design idea, starting from a large-scale software architecture, in order to facilitate upgrades and maintenance. Therefore, it appears many times in the above: reduce dependencies and reduce coupling.

Demeter Principle (Least Knowing Principle) (Demeter Principle)  

Why is it called the principle of least knowledge, that is, an entity should interact with other entities as little as possible, so that the functional modules of the system are relatively independent.

Composite Reuse Principle  

The principle is to use composition/aggregation as much as possible instead of inheritance.  

These are some overviews of JAVA design patterns. Then we will start to study in more detail.


Guess you like

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