I hope you guys can give me some good suggestions. I am thinking how to make a good architecture for C# development. I am trying my best to explain scenarios because im not good at english:
1) Two classes: Blue Bank and Red Bank
2) Third class : Rules Of Validations
3) Blue and Red Banks have several fields (values) such as AccountNumber, Amount, InvoicePeriod etc... Example here (xml):
Blue Bank
<AccountNumber>Maria 5987593457</AccountNumber>
<Amount>200.00</Amount>
<InvoicePeriod>1</InvoicePeriod>
Red Bank
<AccountNumber>8529458</AccountNumber>
<Amount>300.00</Amount>
<InvoicePeriod>0</InvoicePeriod>
Red/Blue Banks have some same rules of validations like Amount fields that must be numberic. But Red/Blue Banks have different rules of validations -- AccountNumber field must be alphanumberic in Blue Bank whereas AccountNumber must be numberic in Red Bank otherwise failed. InvoicePeriod field must be default 1 in Red Bank whereas it must be default 0 in Blue Bank otherwise failed.
My idea is:
I want to create each class of Red / Blue Bank for different rules of validation and then i also create a rules of validation class for the same rules that Blue/Red banks have.
My code here:
Blue Bank class:
Red Bank class:
RulesOfValidation class
How does it work with dictonary <,> with these classes? Or any better suggestion with your example codes?
Your help would be highly appreciated.
Specification Pattern is a good option for your problem. You can create a specification class for common bank rules and others specification classes for each specific need.
There is some c# libraries for this pattern:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With