[Design pattern] ------ Abstract factory pattern

Abstract factory pattern

The abstract factory pattern is to improve the factory method pattern. In fact, it is to create each factory with the routine of the simple factory pattern, and the back is exactly the same as the factory pattern.

In fact, it is equivalent to giving the caller the right to create a new factory.
When calling, the calling end specifies which factory to use, and the object finally obtained is the object corresponding to that factory.

Abstract factory pattern = simple factory pattern + factory method pattern.
Abstract factory pattern = factory factory.

The advantages and disadvantages of the abstract factory pattern:

The advantage is that it is aggregated again, and for the user, there is no need to know the details of the creation.

The disadvantage is that it is relatively complicated. If you want to change it, the impact will be greater.

In addition

The abstract factory pattern is a bit more complicated than the simple factory pattern and the factory method pattern, but it is not necessarily the best to use the abstract pattern, it depends on the situation.

In fact, I haven't encountered any scenes, and this mode is particularly suitable. It's just that I think the reason for this model is more of an idea, that is, the combination of design patterns, focusing on flexibility. I learned so much in one stroke, if I only think about the problem according to the example scenario, it is actually equivalent to not learning much.

Therefore, we must integrate and integrate all the knowledge points of the design patterns and use them together.

Published 203 original articles · praised 186 · 210,000 views

Guess you like

Origin blog.csdn.net/java_zhangshuai/article/details/105213545