6、抽象工厂模式

6、抽象工厂模式    使用一个对象,生产指定的产品(不会参杂其他的产品的东西)

 

namespace SJ.DesignMode
{
    /// <summary>
    /// 设计模式
    /// </summary>
    class Program
    {
        static void Main(string[] args)
        {

            AbstractInstance abstractInstance = new AbstractInstance(new DaiEr());
            abstractInstance.Color();
            abstractInstance.Create();
 
        }
    }

 public abstract class AbstractComputer
    {
        public abstract void Color();

        public abstract void Create();         
    }     

    public class DaiEr : AbstractComputer
    {
        public override void Color() 
        {
            Console.WriteLine("DaiEr Green !");
        }
        public override void Create()
        {
            Console.WriteLine("DaiEr create !");
        }
    }

    public class LianXiang : AbstractComputer
    {
        public override void Color()
        {
            Console.WriteLine("LianXiang Blue !");
        }

        public override void Create()
        {
            Console.WriteLine("LianXiang run !");
        }
    }

    public class AbstractInstance
    {
        AbstractComputer _abstractComputer = null;
        public AbstractInstance(AbstractComputer abstractComputer)
        {
            _abstractComputer = abstractComputer;
        }

        public void Color()
        {
            _abstractComputer.Color();
        }

        public void Create()
        {
            _abstractComputer.Create();
        }
    }
}
 

  

上一篇:oracle 10g和11g的互相导入和导出


下一篇:BAT Windows定时指定任务