static void Main(string[] args) { CookVegetable spinach = new Spinach(); spinach.StartCookingVegetable(); CookVegetable cabbage = new ChineseCabbage(); cabbage.StartCookingVegetable(); Console.Read(); }
static void Main(string[] args) { // 创建一个菠菜实例并调用模板方法 Vegetabel spinach = new Spinach(); spinach.CookVegetabel(); Console.WriteLine(); // 创建一个大白菜实例并调用模板方法 Vegetabel cabbage = new ChineseCabbage(); cabbage.CookVegetabel(); Console.Read(); }
public void TemplateTest() { { var a = new ConcreteClassA(); a.TemplateMethod(); var b = new ConcreteClassB(); b.TemplateMethod(); } { var spinach = new Spinach(); spinach.CookVegetabel(); var chineseCabbage = new ChineseCabbage(); chineseCabbage.CookVegetabel(); } }