一,工厂模式

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace _2._1工厂模式
{
class Program
{
static void Main(string[] args)
{
IPeopleFactory a = new ChinePeople();
Console.Write("中国人人穿了" + a.ShowShoes("红色") + "," + a.ShowClothes("红色"));
IPeopleFactory b = new USAPeople();
Console.Write("美国人穿了" + b.ShowShoes("白色") + "," + b.ShowClothes("白色"));
}
}
public interface IPeopleFactory
{
string ShowShoes(string type);
string ShowClothes(string type);
}
public class ChinePeople : IPeopleFactory
{
public string ShowShoes(string type)
{
return type + "上衣";
}
public string ShowClothes(string type)
{
return type + "裤子";
}
}
public class USAPeople : IPeopleFactory
{
public string ShowShoes(string type)
{
return type + "上衣";
}
public string ShowClothes(string type)
{
return type + "裤子";
}
}
}

二,主要用于隔离类对象的使用者和具体类型之间的耦合关系和实现多态等

与抽象工厂模式的区别在抽象工厂模式中详解

三,有时候我们有种疑惑,为什么我们不使用工厂模式,而使用现在的IOC呢?

其实本质上还是因为IOC是通过反射机制来实现的。当我们的需求出现变动时,工厂模式会需要进行相应的变化。但是IOC的反射机制允许我们不重新编译代码,因为它的对象都是动态生成的。

最新文章

  1. Solve VS2010 Error "Exceptions has been thrown by the target of an invocation"
  2. Oracle监听器启动出错:本地计算机上的OracleOraDb11g_home1TNSListener服务启动后又停止了解决方案
  3. Apche Kafka 的生与死 – failover 机制详解
  4. 项目开发中遇到的extjs常见问题
  5. 用户View,五大布局
  6. CentOS7 升级python同时解决yum损坏问题
  7. C++ 学习资料搜寻与学习(第一期)(未完待续)
  8. 如何在TableView上添加悬浮按钮
  9. ssh登陆笔记📒
  10. mac 下 wget 安装
  11. js生成word中图片处理
  12. The server's host key is not cached in the registry. You have no guarantee that the server……
  13. Asp.net core Razor 页面
  14. 异步Async
  15. ELK菜鸟手记 (二) - 高级配置之多应用索引过滤
  16. Java -- 获取指定接口的所有实现类或获取指定类的所有继承类
  17. 从零开始学习Docker
  18. Spring Cloud构建微服务架构(三)断路器
  19. linux hosts.equiv设置解析
  20. 那些实用的Nginx规则

热门文章

  1. FTP服务器原理及配置
  2. 八个JS中你见过的类型。
  3. 六、MyBatis-缓存机制
  4. Java中的栈和队列
  5. Angular:实现组件间双向数据绑定
  6. 有关CSS的一些事
  7. C# WinForm 中Label自动换行 解决方法
  8. PHP获取时间排除周六、周日的两个方法
  9. 基于canvas实现的高性能、跨平台的股票图表库--clchart
  10. inline-block的间隙问题 box-orient属性 line-clamp属性 margin问题