NOTE. All assemblers are for unit testing only.
So, I created the builders, and as I created them, I began to notice that some of the other developers, already in place, were following a slightly different pattern.
I think I'm asking which one is more effective.
My way to do this is:
public class Builder { public Builders() { SetDefaults(); } private void SetDefaults() {
Another way that is in place:
public class Builder { public Builder WithDefaults() {
In my opinion, the first one is more effective because you just create your own builder and it automatically sets the default settings.
Otherwise, you need to explicitly call the WithDefaults method to set all the defaults before continuing.
The second seems more error prone since some objects that need to be built can throw a null exception if they do not have all of their fields.
Perhaps I missed something subtle here, so I decided to ask you a question about which one is more efficient to move forward.
Thanks.
source share