I'm working on a coarse API for performing higher level business functions. Under many conditions these functions may fail in a way that is expected (not exceptional), ie. the function may not be able to complete because of failing a validation condition of some kind.

In many cases, what I want to do in these "failure" scenarios is to alert the user and give them the option to "override" the failure. ie, "Warning: transferring warp power to the shields will damage the emitter array, are you sure you want to proceed?"

Many of these functions may have a list of quite a few validation rules and I may want to override all of them.

What I'm envisioning right now is to create a custom MyResult class that is returned by the functions that includes whether or not the function succeeded and if it failed, perhaps a list of validation rules that failed for the function. Then add a parameter to the function for "overrides" that allows these validation rules to be bypassed in a subsequent call. I'd like feedback on this approach. Is there a pattern for this?

The functions in the API may be called from multiple platforms and the API itself is in C#.

  • Are you going to be including logic that prevents an override if there has not been at least one failure? May 5, 2014 at 6:51
  • No, probably not. The back end API will probably be called through a web service from different platforms so I'd like to keep things stateless.
    – scotru
    May 5, 2014 at 8:01

2 Answers 2


I wouldn't bother. I'd create a second API call that does no validation for any rule that you feel should be overridable by the user, and then have the client decide to call the validated logic first, and then if the user chooses, call the unvalidated method afterwards. It greatly simplifies the problem so that you don't need to have a whole lot of if() statements wrapping everything.

  • Yea--this seems like it might be a lot simpler solution. My only concern is that if new business validation rules are added to the API, a client may override the new rules unintentionally--but if I made the clients just iterate through a list returned by the API, I guess that wouldn't matter. The client wouldn't need to know the details.
    – scotru
    May 5, 2014 at 7:58

With complex logic like that I would make the "business function" into separate object, quite similar to command pattern. Then, you can have interface like this:

interface IBusinessFunction
    Result Start();
    Result Continue();
    void Cancel();

The Result might indicate, that the function finished or it can indicate it requires user to either override, in which case he executes Continue or Cancel the whole function. The major advantage of this it allows generic handling of those function in UI. The UI just needs to know about this interface to be able to correctly allow overriding or canceling the functions. Also, you don't have to restart the whole function every time it gets aborted and overriden, because it keeps the state in the instance.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.