C#工厂模式案例

class JianDanGongChang
    {
        static void Main(string[] args)
        {
            Factory factory=new LianXiangFactory();
            DianNao dianNao=factory.Create();
            dianNao.Print();
        }
    }
    
    public abstract class DianNao
    {
        public abstract void Print();
    }
    
    public class LianXiang:DianNao
    {
        public override void Print()
        {
            Console.WriteLine("联想电脑");
        }
    }
    
    public class DaiEr:DianNao
    {
        public override void Print()
        {
            Console.WriteLine("戴尔电脑");
        }
    }
    
    public abstract class Factory
    {
        public abstract DianNao Create();
    }
    
    public class LianXiangFactory:Factory
    {
        public override DianNao Create()
        {
            return new LianXiang();
        }
    }
    
    public class DaiErFactory:Factory
    {
        public override DianNao Create()
        {
            return new DaiEr();
        }
    }

 

C#工厂模式案例

上一篇:Delphi 清理程序内存


下一篇:sftp的使用