0
phillip
3y

When do you use parameters in your Dto/ViewModel constructors?
I'm trying to explain to a senior developer, that we don't need to have all parameters for all properties,
we only need it to set default/private fields.

Comments
  • 0
    Sounds like he wants them to be immutable. In which case they have to be in the constructor.

    But even then you can create overloads for constructors that only need minimal set of params with defaults.

    Or private static creation methods, that also works for immutability
  • 0
    @Hazarth No he's not.
    My point is to keep some of the fields immutable.
    His point of view is...
    "It's easier to write var x = new Class1(arg1, arg2, arg3...)
    Than to write
    var x = new Class1{
    Arg1 = something
    .
    .
    .
    }
    (He comes from visual basic background)
  • 0
    @phillip I honestly prefer the builder pattern for that sort of thing if there's a lot of parameters

    Class.builder().withParamA(val).withParamB(val).build()

    much easier to read than Class(a, b, c, d...)...
Add Comment