public abstract class TemplatePattern
{
public void RecipeMethod()
{
SetName();
Ingredients();
Preparation();
Cook();
}
public abstract string SetName();
public abstract Array Ingredients();
public abstract Array Preparation();
public abstract Array Cook();
public sealed class SpanishRice : TemplatePattern
{
string[] ingredients = { "rice", "tomato sauce", "jalapeno chiles", "onions", "frozen peas and carrots", "chili oil" };
string[] preparation = { "Wash rice", "chop chiles", "dice onions" };
string[] cook = { "season pan with oil, onions and chiles", "pan fry rice", "add tomato sauce", "add frozen peas and carrots", "cover", "let stand for 20 min" };
public override string SetName() { return "Spanish Rice"; }
public override Array Ingredients() { return ingredients; }
public override Array Preparation() { return preparation; }
public override Array Cook() { return cook; }
}
public sealed class PorkFriedRice : TemplatePattern
{
string[] ingredients = { "jasmine rice", "pork loin", "onions", "frozen Peas and carrots", "chopped ginger", "chopped garlic", "sesame seek oil", "soy sauce" };
string[] preparation = { "wash rice", "cook rice in rice cooker", "refrigerate rice overnite", "dice pork loin", "dice onions" };
string[] cook = { "season pan with sesame oil, onions, ginger, and garlic", "stir fry pork loin", "add cold rice, soy sauce, and frozen peas and carrots", "stir fry" };
public override string SetName() { return "Pork Fried Rice"; }
public override Array Ingredients() { return ingredients; }
public override Array Preparation() { return preparation; }
public override Array Cook() { return cook; }
}
public sealed class ShrimpFriedRice : TemplatePattern
{
string[] ingredients = { "jasmine rice", "shrimp", "onions", "frozen Peas and carrots", "chopped ginger", "chopped garlic", "sesame seek oil", "soy sauce" };
string[] preparation = { "wash rice", "cook rice in rice cooker", "refrigerate rice overnite", "peel and devein shrimp", "dice onions" };
string[] cook = { "season pan with sesame oil, onions, ginger, and garlic", "stir fry shrimp", "add cold rice, soy sauce, and frozen peas and carrots", "stir fry" };
public override string SetName() { return "Shrimp Fried Rice"; }
public override Array Ingredients() { return ingredients; }
public override Array Preparation() { return preparation; }
public override Array Cook() { return cook; }
}
}//end of Template class
//Controller method
public ActionResult TemplatePattern(string inRecipe)
{
switch (inRecipe)
{
case "SpanishRice":
return View(new SpanishRice());
case "PorkFriedRice":
return View(new PorkFriedRice());
case "ShrimpFriedRice":
return View(new ShrimpFriedRice());
default:
return View();
}
}
//TemplatePattern.cshtml
@model MvcBootstrap.Models.TemplatePattern
@{
ViewBag.Title = "Template Pattern";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<div class="row col-sm-12">
<center>
<div class="row col-sm-12 fontXLargeBoldBlack">Template Pattern</div>
<div class="row col-sm-12 fontLargeBoldBlack">
defines the skeleton of an algorithm in the superclass but lets subclasses override specific steps of the algorithm without changing its structure.
</div>
</center>
</div>
<div class="row rowHeight20px"></div>
<div class="row col-sm-12 fontXLargeBoldRed text-center">Pick a recipe</div>
<div class="row rowHeight20px"></div>
<div class="row col-sm-12 form-check-inline fontLargeBold" id="dvRadioButtons">
<center>
<label class="radio-inline"><input type="radio" name="optradio" value="SpanishRice">Spanish Rice</label>
<label class="radio-inline"><input type="radio" name="optradio" value="PorkFriedRice">Pork Fried Rice</label>
<label class="radio-inline"><input type="radio" name="optradio" value="ShrimpFriedRice">Shrimp Fried Rice</label>
</center>
</div>
@if (Model != null)
{
<div class="row col-sm-12 rowHeight20px"></div>
<div class="row col-sm-12 well border2pxSolidBlack ">
<div class="row fontLargeBold text-center">@Model.SetName()</div>
<div class="col-sm-4">
<div class="fontLargeBold">Ingredients</div>
@foreach (var s in Model.Ingredients())
{
<div class=" paddingLeft25">
@s
</div>
}
</div>
<div class="col-sm-4">
<div class="fontLargeBold">Preparation</div>
@foreach (var s in Model.Preparation())
{
<div class="paddingLeft25">
@s
</div>
}
</div>
<div class="col-sm-4">
<div class="fontLargeBold">Cook</div>
@foreach (var s in Model.Cook())
{
<div class="paddingLeft25">
@s
</div>
}
</div>
</div>
}
else
{
<div class="row col-sm-12 rowHeight200px"></div>
}