2 ms·
If I have five parameters and they all need to be set (otherwise the object is invalid), think of a constructor as a sort of builder pattern that does all five
by janalsncm 2y ago
If I have five parameters and they all need to be set (otherwise the object is invalid), think of a constructor as a sort of builder pattern that does all five at once and avoids checking for invalid states (e.g. you only set 3 of the variables) in other methods.