jeudi 23 novembre 2017

C# how to build logical workflow using predicates and action delegates?

Is there a design pattern that can be applied where I can build sophisticated workflows without having to write multiple conditional and nested conditional statements - I think the answer may lie somewhere in employing something like the Specification Pattern but am unsure how it comes together in C#?

   static void Main()
    {
        // I have some predicates
        bool transientError = true;
        bool fatalError = true;
        bool maxRetriesReached = true;

        // I have some actions
        Action SendToDeadletter = () => { };
        Action Retry = () => { };
        Action Complete = () => { };

        // Is there a way of building the following without using conditional statements
        // something like Specification Pattern?

        // maxRetriesReached || fatalError => SendToDeadletter()
        // transientError && !maxRetriesReached => Retry()
        // !transientError && !fatalError => Complete()

    }

Aucun commentaire:

Enregistrer un commentaire