Click here to Skip to main content
15,889,877 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
want to write this code in simplified way using SOLID principles. Any help would be highly appreciated.Can i implement inheritance to do this.


void CalculateTaxAndRewardPoints()
        {
            if (state == TEXAS)
            {
                rate = TX_RATE;
                amt = baseRate * TX_RATE;
                calc = 2 * basis(amt) + extra(amt) * 1.05;
            }
            else if ((state == OHIO) || (state == MAINE))
            {
                if (state == OHIO)
                    rate = OH_RATE;
                else
                    rate = MN_RATE;
                amt = baseRate * rate;
                calc = 2 * basis(amt) + extra(amt) * 1.05;
                if (state == OHIO)
                    points = 2;
            }
            else
            {
                rate = 1;
                amt = baseRate;
                calc = 2 * basis(amt) + extra(amt) * 1.05;
            }
        }


What I have tried:

void CalculateTaxAndRewardPoints()
        {
            while (state == TEXAS)
            {
                rate = TX_RATE;
                amt = baseRate * TX_RATE;
                calc = 2 * basis(amt) + extra(amt) * 1.05;
            }
            do while ((state == OHIO) || (state == MAINE))
            {
                while (state == OHIO)
                    rate = OH_RATE;
                else
                    rate = MN_RATE;
                amt = baseRate * rate;
                calc = 2 * basis(amt) + extra(amt) * 1.05;
                do while (state == OHIO)
                    points = 2;
            }
            Do while
            {
                rate = 1;
                amt = baseRate;
                calc = 2 * basis(amt) + extra(amt) * 1.05;
            }
        }
Posted
Updated 29-Aug-17 23:35pm

1 solution

Have a read of this CP article (with code examples) on how to implement the Open/Closed principle: SOLID architecture principles using simple C# examples[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900