Click here to Skip to main content
15,886,639 members
Articles / Programming Languages / C#

Who cares about Domain Rules?

Rate me:
Please Sign up or sign in to vote.
4.96/5 (88 votes)
20 Nov 2006MIT12 min read 95.9K   85   118  
With this article, I am evolving a domain problem towards the best possible solution.
namespace BusinessRules.Evolution_One
{
    /// <summary>
    /// Investor Domain object specific to Australia
    /// </summary>
    public class AustralianInvestor : IInvestor
    {
        #region Fields

        private double income;
        private double taxRate;

        #endregion

        #region C'tors

        /// <summary>
        /// Initializes a new instance of the <see cref="AustralianInvestor"/> class.
        /// </summary>
        /// <param name="income">The income.</param>
        public AustralianInvestor(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;

                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;
                }
                return taxLiability;
            }
        }

        /// <summary>
        /// Gets the tax rate.
        /// </summary>
        /// <value>The tax rate.</value>
        public double TaxRate
        {
            get
            {
                double inv_income = Income;
                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;

                return taxRate;
            }
        }

        #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


Written By
Web Developer
New Zealand New Zealand
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions