mardi 29 septembre 2015

Use the Builder Pattern to create mutable objects?

According to the book Design Patterns du Gang of Four,

The Builder Pattern separates the construction of a complex object from its representation so that the same construction process can create different representations.

In general the Builder pattern solves the issue with large number of optional parameters and inconsistent state by providing a way to build the object step-by-step and provide a method that will actually return the final Object.

With the builder pattern we go to have a build method to generate an object witch is immutable.

My Question:

Can I use the builder pattern keeping setters methods in the Class of the generate object, allowing the possibility to mutate the built object ?

If I go to produce mutable objects, I shouldn't use the builder pattern ?

Aucun commentaire:

Enregistrer un commentaire