mercredi 5 avril 2017

Design Pattern for input value that need to be checked within a range - C# examples Preferred

I am wondering what is the best design pattern to be used if the below requirements
1- Input number is coming
2- I need to check this input against a range of static values stored in config file/resource file/lookup table
3- Get set of rules based on on which range it fails within
I must avoid IF statement, switch and I've tried the strategy pattern but It requires creating a sophisticated logic(child class for each range) which I want to avoid
Illustrating example: imagine, I am having a salary and wants to check if it falls within a range of which tax group to apply certain rules this problem is to receive the salary of employee and parse

0   - $18,200    Nil
$18,201 - $37,000    19c    for each    $1  over    $18,200
$37,001 - $80,000    $3,572 plus    32.5c   for each    $1  over    $37,000
$80,001 - $180,000   $17,547    plus    37c for each    $1  over    $80,000
$180,001    and over     $54,547    plus    45c for each    $1  over    $180,000

Aucun commentaire:

Enregistrer un commentaire