The more I think about it, there's really two situ...
# rx
d
The more I think about it, there's really two situations. The null-object pattern makes the most sense when "nully" data can be dealt with transparently alongside with "real" data... for example, an empty list can usually be a sufficient replacement for "the absence of a list of items" because you probably don't care if there actually are any items. In the
User
example, it's much more likely that, when consuming the data, you'd check
if (user == User.NULL)
as a first step. Using
User.NULL
itself has the much higher potential of compromising correctness. For that kind of situtation, I'd much prefer a box... it forces the consumer to check the value and make a decision on its existence, and the correctness can be checked statically much more easily than if you just have to remember to verify your
User
is "real".