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. The following diagram shows the interaction between the actors:
Let's map this pattern in our software house context.
Suppose that our SoftwareHouse
class has a createSoftware()
method that takes a software specification and returns an application...