Small knowledge, big challenge! This article is participating in the creation activity of “Essential Tips for Programmers”.

Writing in the front

Design pattern, in fact, to a certain extent, represents the optimal solution, the best practice, the solution summarized by some developers based on experience, and the optimal solution for different scenarios.

In the current environment, design patterns are also highly respected by developers, and use them to solve many problems, so it is imperative to learn design patterns.

Let’s take a look at the “Heng Yuan pattern”.

The common element pattern, one of the structural design patterns, mainly provides a reduction in the number of objects to effectively improve the memory usage of the program, and effectively improve the performance of the program.

To a certain extent, it can effectively avoid the problem of memory overflow and abstract the common business logic part in the program. When other businesses use it, it can be directly obtained from the memory without occupying too much memory space.

Usage scenarios

The main usage scenario of henyuan mode is to solve the problem of multiple objects occupying memory, and abstract some common modules to solve the problem of insufficient memory.

The advantages and disadvantages

The advantage of the primitive mode is that it can greatly reduce the number of objects created, reduce the memory usage, and improve the overall performance and efficiency.

The downside is increased complexity, because the abstract common module no longer serves only one side, but needs to be compatible with all module functions, which can lead to increased complexity of the program.