Respuesta :
Answer:
Check the explanation
Explanation:
class AssemblyLine
{
// Builder uses a complex series of steps
//
public void Assemble(SandwichBuilder sandwichBuilder)
{
sandwichBuilder.AddMeats();
sandwichBuilder.AddSandwich Number();
sandwichBuilder.AddPrice();
sandwichBuilder.AddCalories();
}
}
class Sandwich
{
private string _sandwichType;
private Dictionary<string, string> _ingredients = new Dictionary<string, string>();
// Constructor
public Sandwich(string sandwichType)
{
this._sandwichType = sandwichType;
}
// Indexer
public string this[string key]
{
get { return _ingredients[key]; }
set { _ingredients[key] = value; }
}
public void Show()
{
Console.WriteLine("\n---------------------------");
Console.WriteLine("Sandwich: {0}", _sandwichType);
Console.WriteLine(" Meat: {0}", _ingredients["meat"]);
Console.WriteLine("Sandwich Number: {0}", _ingredients["sandwich Number"]);
Console.WriteLine(" Price: {0}", _ingredients["price"]);
Console.WriteLine(" Calories: {0}", _ingredients["calories"]);
}
}
abstract class SandwichBuilder
{
protected Sandwich sandwich;
// Gets sandwich instance
public Sandwich Sandwich
{
get { return sandwich; }
}
// Abstract build methods
public abstract void AddMeats();
public abstract void AddSandwich Number();
public abstract void AddPrice();
public abstract void AddCalories();
}
class TurkeyClub : SandwichBuilder
{
public TurkeyClub()
{
sandwich = new Sandwich("Turkey Club");
}
public override void AddMeats()
{
sandwich["meat"] = "Turkey";
}
public override void AddSandwich Number()
{
sandwich["sandwich Number"] = "10";
}
public override void AddPrice()
{
sandwich["price"] = "50";
}
public override void AddCalories()
{
sandwich["calories"] = "361";
}
}
/// <summary>
/// A ConcreteBuilder class
/// </summary>
class BLT : SandwichBuilder
{
public BLT()
{
sandwich = new Sandwich("BLT");
}
public override void AddMeats()
{
sandwich["meat"] = "Bacon";
}
public override void AddSandwich Number()
{
sandwich["sandwich Number"] = "2";
}
public override void AddPrice()
{
sandwich["price"] = "None";
}
public override void AddCalories()
{
sandwich["calories"] = "none";
}
}
/// <summary>
/// A ConcreteBuilder class
/// </summary>
class HamAndCheese : SandwichBuilder
{
public Ham()
{
sandwich = new Sandwich("Ham ");
}
public override void AddSandwhich Number()
{
sandwich["sandwhich number"] = "1";
}
public override void AddMeats()
{
sandwich["meat"] = "Ham";
}
public override void AddPrice()
{
sandwich["price"] = "None";
}
public override void AddCalories()
{
sandwich["calories"] = "none";
}
}
static void Main(string[] args)
{
SandwichBuilder builder;
// Create shop with sandwich assembly line
AssemblyLine shop = new AssemblyLine();
// Construct and display sandwiches
builder = new Ham();
shop.Assemble(builder);
builder.Sandwich.Show();
builder = new BLT();
shop.Assemble(builder);
builder.Sandwich.Show();
builder = new TurkeyClub();
shop.Assemble(builder);
builder.Sandwich.Show();
// Wait for user
Console.ReadKey();
}