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
  • 相关阅读:
    glusterfs 术语
    python 随便
    ubuntu glusterfs 配置调试
    源码生成deb包
    常用apt cli
    unexpected error ConnectionError object has no attribute
    [MFC]透明图展示
    菜鸟的mongoDB学习---(六)MongoDB 索引
    Keyboard的显示与隐藏
    HDU 4268 Alice and Bob(贪心+Multiset的应用)
  • 原文地址:https://www.cnblogs.com/chuifeng/p/1916597.html
Copyright © 2011-2022 走看看