Try and Try Again

Attending MagicRuby this year provided me with many take-aways that I would like to discuss. One of these is that of the NullObject Pattern (NOP). There were a number of great presentations there, and I know this topic probably old hat for some of the longer-bearded fellows, but I really like the idea.

I saw a brief glimpse into the NullObject pattern during Ben Orenstein's talk about refactoring [1]. Essentially, the Null Object pattern allows you to create a neutral object that takes the place of Nil. In fancy terms, the NOP lets the client to ignore the difference between a null operation and a real operation via an abstraction layer.

I know your first question will invariablly be: Why?

The Why

Why would you use the Null Object pattern? Let's go into a simple example.