用C#(.NET Core) 实现简单工厂和工厂方法模式 (2)

using System; using System.Collections.Generic; namespace SimpleFactory.Pizzas { public abstract class Pizza { public string Name { get; protected set; } public string Dough { get; protected set; } public string Sauce { get; protected set; } protected List<string> Toppings = new List<string>(); public void Prepare() { Console.WriteLine($"Preparing: {Name}"); Console.WriteLine($"Tossing: {Dough}"); Console.WriteLine($"Adding sauce: {Sauce}"); Console.WriteLine("Adding toppings: "); Toppings.ForEach(x => Console.WriteLine($" {x}")); } public void Bake() { Console.WriteLine("Bake for 25 minutes"); } public void Cut() { Console.WriteLine("Cutting the pizza into diagnol slices"); } public void Box() { Console.WriteLine("Placing pizza in official PizzaStore box......"); } } }

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wpjpdz.html