工厂模式
来源:互联网 发布:tbc魔兽世界数据库 编辑:程序博客网 时间:2024/06/02 02:14
using System;
using System.Collections.Generic;
using System.Text;
//工厂模式
namespace designMode
{
class LeiFeng
{
public void Sweep()
{
Console.WriteLine("扫地");
}
public void Wash()
{
Console.WriteLine("洗衣");
}
public void BuyRice()
{
Console.WriteLine("买米");
}
}
class Undergraduate : LeiFeng
{
}
class Volunteer : LeiFeng
{
}
interface IFactory
{
LeiFeng CreateLeiFeng();
}
class UndergraduateFactory : IFactory
{
public LeiFeng CreateLeiFeng()
{
return new Undergraduate();
}
}
class VolunteerFactory : IFactory
{
public LeiFeng CreateLeiFeng()
{
return new Volunteer();
}
}
}
static void Main(string[] args)
{
//工厂模式
IFactory factory = new UndergraduateFactory();
LeiFeng student = factory.CreateLeiFeng();
student.BuyRice();
student.Sweep();
student.Wash();
Console.Read();
}
0 0
- 工厂模式 -- 工厂方法
- 工厂模式 -- 抽象工厂
- 工厂模式-简单工厂
- 工厂模式-工厂方法
- 工厂模式:静态工厂
- 工厂模式-简单工厂
- 工厂模式-抽象工厂
- 工厂模式-工厂方法
- 工厂 > 工厂方法模式
- 工厂模式-静态工厂
- 工厂模式-抽象工厂
- 工厂模式
- 工厂模式
- 工厂模式
- 工厂模式
- 工厂模式
- 工厂模式
- 工厂模式
- 装饰者模式
- Nginx的启动过程
- Spring中DataIntegrityViolationEx…
- 代理模式
- NGINX模块(二)
- 工厂模式
- GIS开源库shapeLib的使用方法(一)
- chkconfig命令使用
- java jar包冲突解决方案
- GIS开源库shapeLib的使用方法(二)
- Android && java
- 性能测试工具操作数据库(1) -Jmeter与Mysql
- nodejs:入门
- 多态与继承中多态