The power of constructors
Our input model, SendMoneyCommand, puts a lot of responsibility on its constructor. Since the class is immutable, the constructor’s argument list contains a parameter for each attribute of the class. And since the constructor also validates the parameters, it’s not possible to create an object with an invalid state.
In our case, the constructor has only three parameters. What if we had more parameters? Couldn’t we use the builder pattern to make it more convenient to use? We could make the constructor with the long parameter list private and hide the call to it in the build() method of our builder. Then, instead of having to call a constructor with 20 parameters, we could build an object like this:
We can still let our constructor do the validation so that the builder cannot construct an object with an invalid state.
Sound good? Think about what happens if we have to add another field to SendMoneyCommandBuilder...