码迷,mamicode.com
首页 > 其他好文 > 详细

工厂模式

时间:2015-12-14 10:36:03      阅读:171      评论:0      收藏:0      [点我收藏+]

标签:

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!