Creator mode comparison

Factory method pattern VS builder pattern

The factory method pattern focuses on the way the overall object is created;

The builder mode focuses on the process of component construction, aiming to create a complex object through precise construction step by step.

Give a simple example to illustrate the difference between the two. If you want to create a superman, if you use the factory method model, you will directly produce a superman with infinite power, flying, and wearing underwear;

If you use the builder mode, you need to assemble the hands, head, feet, torso and other parts, and then wear the underwear outside, so a superman is born.

Abstract factory mode VS builder mode

The abstract factory model realizes the creation of a product family. A product family is a series of products: a combination of products with different classification dimensions,

With the abstract factory model, you don't need to care about the construction process, only what products are produced by what factory.

The builder mode requires the product to be built in accordance with a designated blueprint, and its main purpose is to produce a new product by assembling parts.

If the abstract factory model is regarded as an auto parts production factory, which produces products of a product family,

Then the builder mode is a car assembly factory, and a complete car can be returned by assembling parts.

Guess you like

Origin blog.csdn.net/qq_39368007/article/details/113947809