dimanche 24 mai 2020

Is builder pattern about number of arguments in the constructor?

I am learning design pattern. As part of that I am going through the Builder design pattern. The definition says that "The intent of the Builder design pattern is to separate the construction of a complex object from its representation". I am trying to understand what does it mean a "complex object".When I check online people are mentioning if the constructor has more arguments or optional arguments then to use builder object.

Is that explanation is correct? If we have optional parameters then why dont we remove those arguments from the constructor and if the client requires that argument can set using a set method?

If we have more constructor arguments and try to create the object using builder class then there can be a chance where client didnt set some arguments and give a call to final method to get the object.

Aucun commentaire:

Enregistrer un commentaire