工厂模式
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();
}
作者:cjingzm
出处:http://www.cnblogs.com/cjingzm/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。