标签:
class BugerPart
{
}
public class KFCBuger : part
{
public override void Make()
{
Console.WriteLine("KFC汉堡,递到了客户面前");
}
}
public class MBuger : part
{
public override void Make()
{
Console.WriteLine("麦当劳汉堡,递到了客户面前");
}
}
class ChipsPart
{
}
public class KFCChips : part
{
public override void Make()
{
Console.WriteLine("KFC薯条,递到了客户面前");
}
}
public class MChips : part
{
public override void Make()
{
Console.WriteLine("麦当劳薯条,递到了客户面前");
}
}
class Client
{
static void Main(string[] args)
{
MealKFCBuilder kfcbuilder = new MealKFCBuilder();
MealDirector kfcdirector = new MealDirector(kfcbuilder);
kfcdirector.CreateMeal().Make();
Console.WriteLine("kfc套餐打包完毕,用户得到kfc套餐。");
Console.Read();
}
}
class DrinkPart
{
}
public class KFCDrink : part
{
public override void Make()
{
Console.WriteLine("KFC饮料,递到了客户面前");
}
}
public class MDrink : part
{
public override void Make()
{
Console.WriteLine("麦当劳饮料,递到了客户面前");
}
}
public class Meal
{
protected List<part> _parts = new List<part>();
public void AddPart(part part1)
{
_parts.Add(part1);
}
public void Make()
{
foreach (part part1 in _parts)
{
part1.Make();
}
}
}
public abstract class MealBuilder
{
protected Meal _meal = new Meal();
public abstract void BuildBuger();
public abstract void BuildChips();
public abstract void buildDrink();
public Meal GetMeal()
{
return _meal;
}
}
public class MealDirector
{
private MealBuilder _mealbuilder;
public MealDirector(MealBuilder mealbuilder)
{
_mealbuilder = mealbuilder;
}
public Meal CreateMeal()
{
_mealbuilder.BuildBuger();
_mealbuilder.BuildChips();
_mealbuilder.buildDrink();
return _mealbuilder.GetMeal();
}
}
public class MealKFCBuilder:MealBuilder
{
public override void BuildBuger()
{
_meal.AddPart(new KFCBuger());
}
public override void BuildChips()
{
_meal.AddPart(new KFCChips());
}
public override void buildDrink()
{
_meal.AddPart(new KFCDrink());
}
}
public class MealMBuilder:MealBuilder
{
public override void BuildBuger()
{
_meal.AddPart(new MBuger());
}
public override void BuildChips()
{
_meal.AddPart(new MChips());
}
public override void buildDrink()
{
_meal.AddPart(new MDrink());
}
}
public abstract class part
{
public abstract void Make();
}
标签:
原文地址:http://www.cnblogs.com/victorchi/p/5089977.html