Search code examples
c#.netdesign-patternsfactory-patternmethod-chaining

Design Pattern : .NET C# , I have to check 100+ compliance


Design Pattern : .NET , I have to check 100+ compliance. For each compliance I have to create a separate class for it. Which is the best solution/Design pattern to build application which checks all compliance with one go, connecting each compliance to each other ?

As its not yet designed, so I am asking for input for a better designing. Requirements : A compliance check for all the banks. Each bank have different rule set before giving a loan approval and few rule set are based on government norms. Scenario : 1. Common Ruleset for Federal government. 2. Each states have their own rule set. 3. Each bank have their own rule set.

In Project Classname would be like

Class BankOfAmerica
{
//all rules
}

Class Bank2
{
//all rules
}
Class State1
{
//all rules
}
Class State2
{
//all rules
}
Class Country
{
//all rules
}

Now for a single user , I want to check eligibility for a loan against more than one bank including different states and a country.


Solution

  • Looks like the Composite pattern is the answer. You should extract the compliance interface from your 100+ compliancies:

    public interface ICompliance 
    {
        bool IsCompliant {get;}
    }
    

    and implement composite compliance:

    public class ConfjunctionCompositeCompliance 
    {
        IList<ICompliance> compliancies = new List<ICompliance>();
    
        public Add(ICompliance compl) {...}
    
        public bool IsCompliant 
        {
             get { return compliancies.Aggregate(true, (c, a) => c &= a.IsCompliant); }
        }
     }
    

    (of course you can optimize checking for conjunction and disjunction boolean checks)