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)是一种软件开发设计模式.抽象工厂模式提供了一种方式,可以将一组具有同一主题的单独的工厂封装起来.如果比较抽象工 ...
随机推荐
- PostgreSQL Configuration – managing scary settings
When it comes to highly available database servers and configuration, a very important aspect is whe ...
- Leetcode: Mini Parser
Given a nested list of integers represented as a string, implement a parser to deserialize it. Each ...
- Eclipse中进行Gradle+Jetty部署的web项目的断点调试
1.自行配置好build.gradle文件和按照gradle的web项目目录结构规范建立java.resourece和webapp文件夹 可在build.gradle文件中自由设定“http端口” 1 ...
- Codeforce Round #210 Div2
A:对角线为k其他为0 B:利用两个相邻的数一定gcd为1和1与任何数gcd为1错k个位就行了 C:不会做操蛋,好像是因为上一层的始终小于下一层的 好吧C又研究了一下,是个贪心题,不符合的情况先科不考 ...
- codevs 1202 求和
http://codevs.cn/problem/1202/ 1202 求和 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 青铜 Bronze 题解 题目描述 D ...
- mysql错误日志路径
造成该问题的原因有很多,单纯的百度google这个问题,很难找到正确的解决办法,要对症下药测才能解决:1.查看具体错误信息: 按:计算机管理——>系统工具——>事件查看器——>Wi ...
- 从一个例子讲解拷贝构造函数与return
#include "iostream" using namespace std; class Location { public: Location(, ) { X = xx; Y ...
- malloc心得
使用malloc时,要有一种在内存中随机分配一块内存的思想,然后再把分配好的内存的首地址返回来.
- Android bindservice使用
package com.example.myact10; import com.example.myact10.MyService.MyBinder; import android.support.v ...
- SQL Server练习
SQL Server 基本语法: http://www.w3school.com.cn/sql/sql_intro.asp 练习1: 运行语句: USE [Test1] select FNumber, ...