4 replies
by kevlin
Sometimes the answer that leads to cleaner code is not to change your style of evaluation, but to change what you are evaluating. There are cases when a check for null can be eliminated easily by introducing the Null Object pattern:
http://www.two-sdg.demon.co.uk/curbralan/papers/europlop/NullObject.pdf
Kevlin
by rsalcedo
Kevlin,
I was interested in reading the document you mentioned, but the link is not valid. Do you know where else it can be found?
-Ricardo
by rsalcedo
Never mind,
I found it one level up in the directory tree:
http://www.two-sdg.demon.co.uk/curbralan/papers/NullObject.pdf
Definitely. The Null pattern is a great way to eliminate NullPointerExceptions from occuring in your code. [As described in builder.com/TechRepublic e-newsletter dated Mon, 5 Nov 2001, though I'm not aware of an archive to link you to :( ].
Simple example being, when you ask your person-loading code for a person, and the ID you ask for isn't there, it returns NullPerson and not null. NullPerson is a legal person whose name is "" etc.
Hen
This discussion is closed to new replies.
Trending Web Development posts
Sort by Trending