jeudi 29 novembre 2018

Builder pattern - Build() method behaviour

There is a Builder. Programming language is irrelevant.

Which one is correct:

    • you set up the builder
    • you are able to call Build() as many times you like to. So in result you end up with X objects of the same parameters (or even changed parameters if you add more configuration.
    • you set up the builder
    • after Build() call, the builder has to be set up again to be able build another object.

Is there any convention how should the Build() behave?

Both scenarios may be valid. In first scenario you have to copy the values, in second you are able to move the values from builder to created object.

I'd like to properly name the "builders" to be able to distinguish behaviour by just reading the name; code comments are lies, the code always tells the truth.

Aucun commentaire:

Enregistrer un commentaire