lundi 6 mai 2019

Is it ever ok for Builder class constructor to take a non-builder parameter?

Is it ever ok for Builder class constructor to take a non-builder parameter? I see lots of examples on the internet of Builder pattern where constructor takes parameters in the form of builder objects which are members of the parent class being built.

Context:  Class X containing members Y and Z 

Someone I know is doing this differently in two different ways, and they both seem wrong to me. Can anyone clarify the correctness or incorrectness of this for me?

1.  If you have a class XBuilder, passing to its constructor an instance of 
      Y and Z  rather than  YBuilder and ZBuilder
2.  Having a class of XBuilder,  passing it a constructor parameter of X.

There is very little info on the internet about variations of this pattern outside of the norm.

For example, Lombok says here they use a A package private no-args empty constructor : https://projectlombok.org/features/Builder

Aucun commentaire:

Enregistrer un commentaire