Uni assignment requires that we build a pizza app in C# that derives Sauce
from Ingredient
. I have a List<Ingredient>
that is storing objects of both types.
Pizza.cs
calls the method GetInstructions()
which is slightly different in the derived method. Unfortunately Sauce.GetInstructions()
is never being called. As you can see, there's a debug line in there that should pop up a message box when the program is executing that routine but it's not popping up. Can anyone suggest why not?
Pizza.cs
contains the following method:
public string BuildInstructionList()
{ // iterate through list of selected toppings and build a single string for display in the GUI
int count = 1; string instructions = "";
foreach (var i in toppings)
{
instructions = instructions += string.Format("Step {0}: {1}", count, i.GetInstructions());
count++;
}
return instructions;
}
Ingredient.cs
contains:
public virtual string GetInstructions()
{
string instructionLine;
string qty = this.GetIngredientQuantity().ToString();
string unit = this.GetIngredientUnit();
string name = this.GetIngredientName();
instructionLine = string.Format("Add {0} {1} of {2} to the pizza.\n", qty, unit, name);
return instructionLine;
}
Sauce.cs
contains:
public new string GetInstructions()
{
PizzaGUI.Message("I am here!");
string instructionLine;
string qty = this.GetIngredientQuantity().ToString();
string unit = this.GetIngredientUnit();
string name = this.GetIngredientName();
instructionLine = string.Format("Apply {0} {1} of {2} to the pizza.\n", qty, unit, name);
return instructionLine;
}