c# 之抽象工厂模式
Email整体项目
Email类 using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Service; namespace Email
{
public class email:Ifiles
{
public void GetEmail()
{
Console.WriteLine("发送邮件了");
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Service;
namespace Email
{
public class EmailFactory:IfileFactory
{
public Ifiles Create()
{
return new email();
}
} //public class EmailFactory : PhoneFactory
//{
// public Phone Create()
// {
// return new Phones();
// }
//}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Service; namespace Email
{
//public class Phones:Phone
// {
// public void GetPhone()
// {
// Console.WriteLine("发送短信了");
// }
// }
}
引用其他类
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text; namespace Service
{
public interface Ifiles
{
void GetEmail();
} //public interface Phone
//{
// void GetPhone();
//}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text; namespace Service
{
public interface IfileFactory
{
Ifiles Create();
} //public interface PhoneFactory
//{
// Phone Create();
//}
}
抽象
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Service;
using System.Reflection; namespace Email
{
class AbstractFactory
{ public Static IfileFactory GetInstace()
{
string names= System.Configuration.ConfigurationManager.AppSettings[""].ToString(); return (Service.IfileFactory)Assembly.Load(names).CreateInstance(names + ".EmailFactory");
}
}
}
使用
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Service; namespace Email
{
class Program
{
static void Main(string[] args)
{
Ifiles em = (new EmailFactory()).Create();
em.GetEmail();
Console.ReadKey();
}
}
}
c# 之抽象工厂模式的更多相关文章
- PHP设计模式(三)抽象工厂模式(Abstract Factory For PHP)
一.什么是抽象工厂模式 抽象工厂模式的用意为:给客户端提供一个接口,可以创建多个产品族中的产品对象 ,而且使用抽象工厂模式还要满足以下条件: 系统中有多个产品族,而系统一次只可能消费其中一族产品. 同 ...
- 面向对象设计模式纵横谈:Abstract Factory 抽象工厂模式(笔记记录)
今天是设计模式的第二讲,抽象工厂的设计模式,我们还是延续老办法,一步一步的.演变的来讲,先来看看一个对象创建的问题. 1.如何创建一个对象 常规的对象创建方法: 这样的创建对象没有任何问题, ...
- Objective-C 工厂模式(下) -- 抽象工厂模式
相比简单工厂模式, 只有一个工厂 能生产的手机也是固定的 抽象工厂模式类似于有很多家工厂, 当用户要买什么手机就创建对应的工厂去生产 比如用户要买iPhone就创建一个Apple工厂来生产手机, 要买 ...
- Net设计模式实例之抽象工厂模式(Abstract Factory Pattern)
一.抽象工厂模式简介(Bref Introduction) 抽象工厂模式(Abstract Factory Pattern),提供一个创建一系列相关或者相互依赖对象的接口,而无需制定他们的具体类.优点 ...
- .NET设计模式(2):1.2 抽象工厂模式(Abstract Factory)
概述 抽象工厂模式(Abstract Factory)是所有形态的工厂模式中最为抽象和最具一般性的一种形态.抽象工厂模式是指当有多个抽象角色时,使用的一种工厂模式.抽象工厂模式可以向客户端提供一个接口 ...
- 设计模式(四)抽象工厂模式(Abstract Factory Pattern)
一.引言 在上一专题中介绍了工厂方法模式,工厂方法模式是为了克服简单工厂模式的缺点而设计出来的,简单工厂模式的工厂类随着产品类的增加需要增加额外的代码,而工厂方法模式每个具体工厂类只完成单个实例的创建 ...
- php实现设计模式之 抽象工厂模式
<?php /*抽象工厂模式:提供一个创建一系统相关或相互依赖对象的接口,而无需指定它们具体的类 * 创建型模式 */ //抽象小米工厂,能制造小米一,小米二 abstract class mi ...
- 设计模式(3)--抽象工厂模式(Absrtact Factory Pattern)
定义 抽象工厂模式的实质就是提供接口来创建一系列相关或独立的对象而不指定这些对象的具体类. 理解 在软件系统中,经常面临着"一系列相互依赖的对象"的创建工作:同时由于需求的变化,往 ...
- Java设计模式(三) 抽象工厂模式
原创文章,同步发自作者个人博客,转载请注明出处 http://www.jasongj.com/design_pattern/abstract_factory/ 抽象工厂模式解决的问题 上文<工厂 ...
- 抽象工厂模式 shiyanlou
二.什么是 抽象工厂模式 抽象工厂模式(Abstract Factory Pattern)是一种软件开发设计模式.抽象工厂模式提供了一种方式,可以将一组具有同一主题的单独的工厂封装起来.如果比较抽象工 ...
随机推荐
- Hadoop2.2.0 第一步完成MapReduce wordcount计算文本数量
1.完成Hadoop2.2.0单机版环境搭建之后需要利用一个例子程序来检验hadoop2 的mapreduce的功能 //启动hdfs和yarn sbin/start-dfs.sh sbin/star ...
- wampserver环境下,安装ucenter1.6.0
1,)从官网下载UCenter_1.6.0_SC_UTF8.zip,解压拷贝upload到www下,重命名upload->ucenter; 2,)D:\wamp\bin\apache\Apach ...
- PostgreSQL9.1 upgrade to PostgreSQL9.5rc1
PostgreSQL9.1.0 upgrade to PostgreSQL9.5rc1 安装PG9.1端口为5432 [pgup@minion1 pg]$ ls postgresql-9.1.0.ta ...
- Leetcode: Combination Sum IV && Summary: The Key to Solve DP
Given an integer array with all positive numbers and no duplicates, find the number of possible comb ...
- 如何抠PSD素材中的图片
在网上经常可以找到一些好看呢的PSD素材,如何才能将这些素材抠出来 存成一张张的png图片呢? 在PhotoShop中 1·隐藏无用的图层,然后窗口中仅剩需要看到的那个素材图 2·用工具选择该区域(注 ...
- 最大权闭合图最大获益(把边抽象为点)HDU3879
题意:给出一个无向图,每个点都有点权值代表花费,每条边都有利益值,代表形成这条边就可以获得e[i]的利益,问选择那些点可以获得最大利益是多少? 分析:把边抽象成点,s与该点建边,容量是利益值,每个点与 ...
- JSP里比对单选框或复选框的数值而自动打勾
<table> <tr> <td class="tableleft">状态</td> <td><input typ ...
- C#写好的类库dll怎么在别人调用的时候也能看到注释?
菜单 Project -> 'xxxx' Properties -> Build -> Output -> 勾上 XML Documentation file
- 关于linux的systemd的一些事
1. 输出运行失败的单元: systemctl --failed 2. 所有的单元文件存放在 /usr/lib/systemd/system/ 和 /etc/systemd/system/ 这两个目录 ...
- equals和==
在初学Java时,可能会经常碰到下面的代码: 1 String str1 = new String("hello"); 2 String str2 = new String(&qu ...