I recently had to deal with a similar case while refactoring some legacy code.
My approach to create valid entities was achieved via factory functions. In a nutshell you can have a
Senior Software Engineer at Noom, formerly Team Lead Engineering at XING. I intend to write about functional programming and occasionally some random engineering topic.
That is a clever usage of interfaces!
I recently had to deal with a similar case while refactoring some legacy code.
My approach to create valid entities was achieved via factory functions. In a nutshell you can have a
which tricks the dev to think that is using a constructor but at the same time keeps everything valid and readable.
If you are interested I wrote a blog post here.
Interesting blog post, thanks! I like that increasingly more people are aware of this problem :)
As for the suggestion, I'd advise against doing it that way because it goes against the conventions:
null
.My 2 cents.
Both arguments are valid. Especially the second one didn't even crossed my mind. Thank you!