• 超级工厂模式


     public interface ISalary
        {
            void CommandSalary();
        }
    public abstract class ShenZhenSalary : ISalary
        {
            public virtual void CommandSalary()
            {
                Console.WriteLine("这是深圳子公司的工资计算模块");
            }
        }
     public abstract class BeiJinSalary : ISalary
        {
            public virtual void CommandSalary()
            {
                Console.WriteLine("这是北京子公司的工资计算模块");
            }
        }
    public class BeiJinItdSalary : BeiJinSalary
        {
            public override void CommandSalary()
            {
                Console.WriteLine("这是北京子公司ITD的工资计算模块");
            }
        }
    
        public class BeiJinHraSalary : BeiJinSalary
        {
            public override void CommandSalary()
            {
                Console.WriteLine("这是北京子公司HRA的工资计算模块");
            }
        }
    public class ShenZhenItdSalary : ShenZhenSalary
        {
            public override void CommandSalary()
            {
                Console.WriteLine("这是深圳子公司ITD的工资计算模块");
            }
        }
    
        public class ShenZhenHraSalary : ShenZhenSalary
        {
            public override void CommandSalary()
            {
                Console.WriteLine("这是深圳子公司HRA的工资计算模块");
            }
        }
    public interface IFactory
        {
            ShenZhenSalary CreateShenZhenSalary();
            BeiJinSalary CreateBeiJinSalary();
        }
    public class ItdFactory : IFactory
        {
            public ShenZhenSalary CreateShenZhenSalary()
            {
                return new ShenZhenItdSalary();
            }
            public BeiJinSalary CreateBeiJinSalary() 
            {
                return new BeiJinItdSalary();
            }
        }
    public class HraFactory:IFactory
        {
           public ShenZhenSalary CreateShenZhenSalary()
           {
               return new ShenZhenHraSalary();
           }
           public BeiJinSalary CreateBeiJinSalary()
           {
               return new BeiJinHraSalary();
           }
        }
    class Program
        {
            public static void Main(string[] args)
            {
                IFactory Factory = new ItdFactory();  //实例化Itd工厂类
                ShenZhenSalary SalarySzItd = Factory.CreateShenZhenSalary();
                SalarySzItd.CommandSalary(); //调用深圳ITD公司计算过程
    
                BeiJinSalary SalaryBjItd = Factory.CreateBeiJinSalary();
                SalaryBjItd.CommandSalary(); //调用北京ITD公司计算过程
    
                Factory = new HraFactory(); //实例化Hra工厂类
                ShenZhenSalary SalarySzHra = Factory.CreateShenZhenSalary();
                SalarySzHra.CommandSalary(); //调用深圳Hra公司计算过程
    
                BeiJinSalary SalaryBjHra = Factory.CreateBeiJinSalary();
                SalaryBjHra.CommandSalary(); //调用北京Hra公司计算过程
    
                Console.ReadLine();
            }
        }
  • 相关阅读:
    Spring学习(一):理解IoC容器
    Spring学习(零):我们为什么要学习Spring
    git push提交报错,提示文件过大,且去掉大文件也报同样的错误
    There was a problem with the instance info replicator
    Eureka配置instanceId显示IP
    Cannot execute request on any known server或DiscoveryClient_UNKNOWN/DESKTOP-MQ8D0C9:8761
    Hexo优化 | 创建sitemap站点地图并向Google提交
    matlab与python读取tiff文件
    Visual studio中编译和使用libpng和zlib
    关于softmax、argmax、softargmax
  • 原文地址:https://www.cnblogs.com/mrhgw/p/3012873.html
Copyright © 2020-2023  润新知