O'Reilly logo

Mastering JavaScript Object-Oriented Programming by Andrea Chiarelli

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The builder pattern

Another way to delegate the task of creating objects to another object is using the builder pattern. This pattern is used to create complex objects that usually require a step-by-step approach.

In the classical definition, this pattern involves the following actors:

  • The client: This is the object that needs a new object
  • The director: This is the actor who knows how to create an object, that is, it knows the necessary steps to get an object built
  • The builder: This actor actually builds the object by providing methods used by the director
  • The product: It is the resulting object built by the builder under the control of the director

In a nutshell, the client asks for a product from the director, who creates it by means of the builder. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required