1,128
99.9
Mar 29, 2011
I guess there are many examples, but I particularily find it useful when working with the Command Pattern.
Say you build a Server that takes some input, given a specific input a command is executed. When faulty data is sent to the server I create a Null Object Command instead of null which does nothing when executed. This keeps me from checking for null.
Just my 2c :)
1,284
100.0
Mar 30, 2011
It is of immense use in huge data centric application as well. For e.g. many financial/banking industries there are lots of calculations that happens in bulk mode wherein you read lots of data and some processing happens on that. It may be millions in numbers. This pattern comes in very handy (as I have faced situations like this many time).
Create a null object for the said entity and process everything in bulk. The null object logs the state and the processing is continued without being interrruped to unwanted null exceptions (note if they happen they are automatically logged :))...
Though this can be done without using NULL Object pattern, but you can imagine the no. of not null check that you need to make for this....