I was looking at the null object pattern and i am wondering if it worths implementing it or use "if" checks for nulls in my code intsead. As i looked at the implementations it seems hard to keep objects well synchronized with their null implementations. By making changes to the main object we have to check that the null object behaves as expected and its easy to make implementation errors. Isn't it ?
EDIT
Avoid checking for null: http://www.invisible-city.com/sharon/2009/03/null-object-pattern-when-slacker-is.html or http://journalofasoftwaredev.wordpress.com/2008/08/19/null-object-pattern-by-example/
If your object being null is going to be a norm throughout your code, you'd might as well use the pattern. I check for null when an object has not been created and it needs to be instantiated. I do not really use null for anything else, and I certainly don't use it to mean no behavior defined.
If however, you are using null to mean the behavior hasn't been defined yet or the default behavior is nothing, then certainly use the pattern.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With