alphagov/frontend — comment on commit 16dbd64b3a9bce89a50c48684c5c519d7ce6c4c9
File: app/controllers/root_controller.rb line 139
By craigw:

I'm a big fan of this approach and I'd like to see it done in other places too; it clears up an awful lot of code and removes a lot of conditionals.

I usually implement NullObject by providing a Singleton, in this case `MissingArtefact`, which implements all the methods of `Artefact` with sane missing values, and I provide a `#missing?` method on all domain objects; the NullObjects return true and everything else returns false.

There are a few advantages to this approach:
* In eg Publisher we can easily detect when something might need data added to Panopticon using `#missing?`
* One clear place to edit missing object behaviour
* Singleton means we don't have a billion copies of an object without unique behaviour in memory

Are you interested in exploring this approach?