标签:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace 工厂模式
{
public interface AbstractFactory
{
Coat ProCoat();
Trousers ProTrousers();
}
public class BusinessFactory : AbstractFactory
{
public Coat ProCoat()
{
return new BusinessCoat();
}
public Trousers ProTrousers()
{
return new BusinessTrousers();
}
}
public class SoftFactory : AbstractFactory
{
public Coat ProCoat()
{
return new SoftCoat();
}
public Trousers ProTrousers()
{
return new SoftTrousers();
}
}
public class FashionFactory : AbstractFactory
{
public Coat ProCoat()
{
return new FashionCoat();
}
public Trousers ProTrousers()
{
return new FashionTrousers();
}
}
public interface Coat
{
}
public interface Trousers
{
}
public class BusinessCoat : Coat
{
public BusinessCoat()
{
Console.WriteLine("商业装上衣");
}
}
public class SoftCoat : Coat
{
public SoftCoat()
{
Console.WriteLine("休闲装上衣");
}
}
public class FashionCoat : Coat
{
public FashionCoat()
{
Console.WriteLine("潮流装上衣");
}
}
public class BusinessTrousers : Trousers
{
public BusinessTrousers()
{
Console.WriteLine("商业装下裤");
}
}
public class SoftTrousers : Trousers
{
public SoftTrousers()
{
Console.WriteLine("休闲装下裤");
}
}
public class FashionTrousers : Trousers
{
public FashionTrousers()
{
Console.WriteLine("潮流装下裤");
}
}
class Program
{
static void Main(string[] args)
{
AbstractFactory bussiness = new BusinessFactory();
bussiness.ProCoat();
bussiness.ProTrousers();
Console.WriteLine();
AbstractFactory soft = new SoftFactory();
soft.ProCoat();
soft.ProTrousers();
Console.WriteLine();
AbstractFactory fash = new FashionFactory();
fash.ProCoat();
fash.ProTrousers();
Console.WriteLine();
Console.ReadLine();
}
}
}
标签:
原文地址:http://www.cnblogs.com/pcc5201314/p/5044206.html