首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> C語言 >> 關於C語言

C# 設計模式:抽象工廠模式深度解析(四)— 美企薪資系統獨立實作

     編輯:關於C語言

美企薪資計算規則

  • 基本薪資:$4,000(常數)
  • 獎金:基本薪資 × 10%
  • 個人所得稅:(基本薪資 + 獎金) × 40%

完整代碼實作

namespace AmericanSalary
{
    public class Constant
    {
        public static double BASE_SALARY = 4000;
    }

    public class AmericanBonus
    {
        public double Calculate() => Constant.BASE_SALARY * 0.1;
    }

    public class AmericanTax
    {
        public double Calculate() => (Constant.BASE_SALARY + Constant.BASE_SALARY * 0.1) * 0.4;
    }

    public class Calculator
    {
        public static void Main(string[] args)
        {
            AmericanBonus bonus = new AmericanBonus();
            AmericanTax tax = new AmericanTax();

            double salary = Constant.BASE_SALARY + bonus.Calculate() - tax.Calculate();
            Console.WriteLine("American Salary is:" + salary);  // 輸出: 2640
            Console.ReadLine();
        }
    }
}

執行結果驗證

基本薪資: 4000
獎金: 400 (10%)
應稅所得: 4400
所得稅: 1760 (40%)
實發薪資: 4000 + 400 - 1760 = 2640

架構局限性

此版本為獨立專案,與中企版本完全分離。若系統需同時支援多國、動態切換,必須整合雙方業務規則並引入抽象層——這正是後續章節要解決的問題。

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved