educative.io

Educative

Builder Pattern,

I don’t see the advantage of using the builder pattern in the aircraft example.

A f16 cannot exist without an engine, so the director always has to create an engine, what’s the benefit over the factory pattern? Also, the f16 builder should know that it doesn’t have a bathroom so it doesn’t need a director to take over this decision.

Besides that, not using methods of an interface violates SOLID’s interface segregation principle (letter I).

I feel like it only makes sense to use the builder pattern if there are optional steps, e.g. like in the document example where you might not want to set an author.

1 Like

Hi @Daniel11

Factory Method is a creational design pattern that provides an interface for creating objects in a superclass, but allows subclasses to alter the type of objects that will be created. Here we use builder pattern because it separates the construction of a complex object from its representation so that the same construction process can create different representations. We use it mostly when objects can’t be created in a single step like in the de-serialization of a complex object.