Consider the following check. I can find the same identical error check 10 times across my solution.
if (request == null)
throw GetFaultException("Request object is null");
Now consider the next one:
if (model == null)
throw GetFaultException("Request model not well formed");
The only stuff that is changing is the error message and the name of the checked variable.
One part of refactoring had already been done since the GetFaultException is already hiding complexity and separating responsibilities.
I see many possible further refactoring. Like using Monads, AOP, events (?).
I think the really really best solution would be to make the code thinking like in a MVC model.
Thus if (condition) request == null then (it means) A mandatory parameter has not been specified then (it means) An exception is needed with a specific message
The good stuff I see in this approach is that the procedural programming makes the code unspeaking and unaware. Instead if I raise a NullMandatoryParameterEvent
it's really clear why I'm checking a variable for being null and what I do if it is null.
The question is: how would you refactor this kind of Check (according to the objective I've defined)? And do you share these objectives?