I like the concept of immutability. I also like the concept of no nulls (and if possible also no NullDesignPattern, no NullObjects... as much as possible).
But what about the following scenario:
I have an object User
, which has two fields: birthday
and dateInLifeMarried
(could be any similar field; the important thing is that at first this field is null
and changes at some point in object life).
As it's immutable I want both fields to be in the constructor:
public User(birthday, dateInLifeMarried)
Now:
- I don't want to pass
null
to the second parameter - I don't want to add a setter becuase its immutable
- i don't want to call the constructor with NullObjectPattern instead of
null
Am i just contradicting myself or is there an elegant way to have it which i'm not thinking of?