zoukankan      html  css  js  c++  java
  • 设计模式学习笔记——工厂方法(Factory Method)

    学习TerryLee的设计模式颇有感触,留下以下笔记以作日后参考。

    代码
    //-----------------------------------------------
    //工厂方法是简单工厂的扩展。
    //工厂方法不只是将类的创建推向了客户端更把创建的逻辑推向了客户端。
    //-----------------------------------------------

    #region 产品

    public interface ICoat
    { }

    public class ACoat : ICoat
    { }

    public class BCoat : ICoat
    { }

    public class CCoat : ICoat
    { }

    #endregion

    #region 工厂

    public interface IFactory
    {
    ICoat CreateCoat();
    }

    public class AFactory : IFactory
    {
    #region IFactory Members

    public ICoat CreateCoat()
    {
    throw new NotImplementedException();
    }

    #endregion
    }

    public class BFactory : IFactory
    {
    #region IFactory Members

    public ICoat CreateCoat()
    {
    throw new NotImplementedException();
    }

    #endregion
    }

    public class CFactory : IFactory
    {
    #region IFactory Members

    public ICoat CreateCoat()
    {
    throw new NotImplementedException();
    }

    #endregion
    }

    #endregion

    #region 客户端

    public class App
    {
    public static void Main(string[] args)
    {
    string strfactoryName = "AFactory";
    IFactory factory;
    factory
    = (IFactory)Assembly.Load("FactoryMethod").CreateInstance("FactoryMethod." + strfactoryName);
    ICoat log
    = factory.CreateCoat();
    }
    }

    #endregion
  • 相关阅读:
    input输入框只能输入数字和 小数点后两位
    HAVING 子句
    GROUP BY 语句
    SUM()函数
    COUNT()函数
    MySQL AVG() 函数
    adb(16)-查看实时资源占用情况top
    adb(15)-刷机相关命令
    adb(14)-设备重启/检测root
    adb(13)-设置系统日期和时间
  • 原文地址:https://www.cnblogs.com/chuifeng/p/1916597.html
Copyright © 2011-2022 走看看