Click here to Skip to main content
12,301,418 members (61,088 online)
Click here to Skip to main content

Stats

73.6K views
64 downloads
116 bookmarked
Posted

Who cares about Domain Rules?

, 20 Nov 2006 MIT
With this article, I am evolving a domain problem towards the best possible solution.
BusinessRules
0 - Procedural_Way
0 - Procedural_Way.smp
ProceduralWay.cd
Tests
1 - Evolution One
1 - Evolution One.smp
EvolutionOne.cd
Tests
2 - Evolution Two
2 - Evolution Two.smp
EvolutionTwo.cd
Tests
3 - Evolution Three
3 - Evolution Three.smp
EvolutionThree.cd
IncomeTaxEngine.cd
Tests
4 - Evolution Four
4 - Evolution Four.smp
EvolutionFour.cd
Tests
5 - Evolution Five
5 - Evolution Five.smp
EvolutionFive.cd
TaxBandGenerator.cd
Tests
bin
Debug
BusinessRules.dll
BusinessRules.dll.lastcodeanalysissucceeded
NMock2.dll
BusinessRules.csproj.user
obj
Debug
BusinessRules.dll
TempPE
Properties
Tools
NMock2.dll
nunit.framework.dll
using System.Globalization;

namespace BusinessRules.Procedural_Way
{
    /// <summary>
    /// Investor Domain object
    /// </summary>
    public class Investor
    {
        #region Fields

        private double income;
        private string m_currentCultureName = CultureInfo.CurrentCulture.Name;

        #endregion

        #region C'tors

        /// <summary>
        /// Initializes a new instance of the <see cref="Investor"/> class.
        /// </summary>
        /// <param name="income">The investors income.</param>
        public Investor(double income)
        {
            this.income = income;
        }

        #endregion

        #region Properties

        /// <summary>
        /// Gets or sets the income.
        /// </summary>
        /// <value>The income.</value>
        public double Income
        {
            get { return income; }
            set { income = value; }
        }

        /// <summary>
        /// Gets the tax liability.
        /// </summary>
        /// <value>The tax liability.</value>
        public double TaxLiability
        {
            get
            {
                double taxLiability = 0.0;
                double inv_income = Income;

                switch (CurrentCultureName)
                {
                    case "en-NZ":
                        // Calculate the Tax Liability for the Investor according 
                        // to the tax laws of the New Zealand
                        if (inv_income > 19500.99)
                        {
                            taxLiability += 19500.99 * 0.195;
                        }
                        if (inv_income <= 19500.99)
                        {
                            taxLiability += inv_income * 0.195;
                        }
                        if (inv_income > 60000.99)
                        {
                            taxLiability += (60000.99 - 19501.00) * 0.33;
                        }
                        if (inv_income >= 19501.00 && inv_income <= 60000.99)
                        {
                            taxLiability += (inv_income - 19501.00) * 0.33;
                        }
                        if (inv_income > 60000.99)
                        {
                            taxLiability += (inv_income - 60000.99) * 0.39;
                        }
                        break;
                    case "en-AU":
                        // Calculate the Tax Liability for the Investor according 
                        // to the tax laws of the Australia
                        if (inv_income >= 6001.00 && inv_income <= 25000.99)
                        {
                            taxLiability += (inv_income - 6000.99) * 0.15;
                        }
                        if (inv_income > 25000.99)
                        {
                            taxLiability += (25000.99 - 6001.00) * 0.15;
                        }
                        if (inv_income > 75000.99)
                        {
                            taxLiability += (75000.99 - 25001.00) * 0.30;
                        }
                        if (inv_income >= 25001.00 && inv_income <= 75000.99)
                        {
                            taxLiability += (inv_income - 25001.00) * 0.30;
                        }
                        if (inv_income > 150000.99)
                        {
                            taxLiability += (150000.99 - 75001.00) * 0.40;
                        }
                        if (inv_income >= 75001.00 && inv_income <= 150000.99)
                        {
                            taxLiability += (inv_income - 75001.00) * 0.40;
                        }
                        if (inv_income > 150000.99)
                        {
                            taxLiability += (inv_income - 150000.99) * 0.45;
                        }
                        break;
                    case "en-US":
                        // Calculate the Tax Liability for the Investor according 
                        // to the tax laws of the USA
                        if (inv_income > 7550.99)
                        {
                            taxLiability += 7550.99 * 0.10;
                        }
                        if (inv_income >= 0.0 && inv_income <= 7550.99)
                        {
                            taxLiability += inv_income * 0.10;
                        }
                        if (inv_income > 30650.99)
                        {
                            taxLiability += (30650.99 - 7551.00) * 0.15;
                        }
                        if (inv_income >= 7551.00 && inv_income <= 30650.99)
                        {
                            taxLiability += (inv_income - 7551.00) * 0.15;
                        }
                        if (inv_income > 74200.99)
                        {
                            taxLiability += (74200.99 - 30651.00) * 0.25;
                        }
                        if (inv_income >= 30651.00 && inv_income <= 74200.99)
                        {
                            taxLiability += (inv_income - 30651.00) * 0.25;
                        }
                        if (inv_income > 154800.99)
                        {
                            taxLiability += (154800.99 - 74201.00) * 0.28;
                        }
                        if (inv_income >= 74201.00 && inv_income <= 154800.99)
                        {
                            taxLiability += (inv_income - 74201.00) * 0.28;
                        }
                        if (inv_income > 336550.99)
                        {
                            taxLiability += (336550.99 - 154801.00) * 0.33;
                        }
                        if (inv_income >= 154801.00 && inv_income <= 336550.99)
                        {
                            taxLiability += (inv_income - 154801.00) * 0.33;
                        }
                        if (inv_income > 336551.00)
                        {
                            taxLiability += (inv_income - 336551.00) * 0.35;
                        }
                        break;
                    default:
                        taxLiability = 0.0;
                        break;
                }
                return taxLiability;
            }
        }

        /// <summary>
        /// Gets the tax rate.
        /// </summary>
        /// <value>The tax rate.</value>
        public double TaxRate
        {
            get
            {
                double taxRate;
                double inv_income = Income;

                switch (CurrentCultureName)
                {
                    case "en-NZ": // Calculate the tax rate for New Zealand
                        if (inv_income >= 0.0 && inv_income <= 19500.99)
                            taxRate = 0.195;
                        else if (inv_income >= 19501.00 && inv_income <= 60000.99)
                            taxRate = 0.33;
                        else
                            taxRate = 0.39;
                        break;
                    case "en-AU": // Calculate the tax rate for Australia
                        if (inv_income >= 0.0 && inv_income <= 6000.99)
                            taxRate = 0.0;
                        else if (inv_income >= 6001.00 && inv_income <= 25000.99)
                            taxRate = 0.15;
                        else if (inv_income >= 25001.00 && inv_income <= 75000.99)
                            taxRate = 0.30;
                        else if (inv_income >= 75001.00 && inv_income <= 150000.99)
                            taxRate = 0.40;
                        else
                            taxRate = 0.45;
                        break;
                    case "en-US": // Calculate the tax rate for the United States of America
                        if (inv_income >= 0.0 && inv_income <= 7550.99)
                            taxRate = 0.10;
                        else if (inv_income >= 7551.00 && inv_income <= 30650.99)
                            taxRate = 0.15;
                        else if (inv_income >= 30651.00 && inv_income <= 74200.99)
                            taxRate = 0.25;
                        else if (inv_income >= 74201.00 && inv_income <= 154800.99)
                            taxRate = 0.28;
                        else if (inv_income >= 154801.00 && inv_income <= 336550.99)
                            taxRate = 0.33;
                        else
                            taxRate = 0.35;
                        break;
                    default:
                        taxRate = 0.0;
                        break;
                }
                return taxRate;
            }
        }

        /// <summary>
        /// Gets or sets the name of the current culture.
        /// </summary>
        /// <value>The name of the current culture.</value>
        public string CurrentCultureName
        {
            get { return m_currentCultureName; }
            set { m_currentCultureName = value; }
        }

        #endregion
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The MIT License

Share

About the Author

Maruis Marais
Web Developer
New Zealand New Zealand
No Biography provided

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160525.2 | Last Updated 21 Nov 2006
Article Copyright 2006 by Maruis Marais
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid