Good case for a Null Object Pattern? (Provide some service with a mailservice)
- by fireeyedboy
For a website I'm working on, I made an Media Service object that I use in the front end, as well as in the backend (CMS). This Media Service object manipulates media in a local repository (DB); it provides the ability to upload/embed video's and upload images.
In other words, website visitors are able to do this in the front end, but administrators of the site are also able to do this in the backend.
I'ld like this service to mail the administrators when a visitor has uploaded/embedded a new medium in the frontend, but refrain from mailing them when they upload/embed a medium themself in the backend.
So I started wondering whether this is a good case for passing a null object, that mimicks the mail funcionality, to the Media Service in the backend. I thought this might come in handy when they decide the backend needs to have implemented mail functionality as well.
In simplified terms I'ld like to do something like this:
Frontend:
$mediaService = new MediaService( new MediaRepository(), new StandardMailService() );
Backend:
$mediaService = new MediaService( new MediaRepository(), new NullMailService() );
How do you feel about this? Does this make sense? Or am I setting myself up for problems down the road?