Nulls Break Polymorphism, Revisited

Steve Smith wrote this post regarding the problem with null about two years ago.  It’s definitely worth reading in full (as is pretty much anything Steve Smith writes).  The post provided code for the implementation of an extension method and a change in the main code that would address null without throwing an exception.  It also mentioned the null object design pattern but didn’t provide a code example.

I took the code from the original post and revised it to use the null object design pattern.  Unlike the original example, my version of the Employee class overrides ToString() instead of using an extension method.  There are almost certainly any number of other tweaks which could be made to the code which I may make later.

Smith’s post links additional material that’s also worth checking out: