using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace _021模板模式
{
public abstract class CookVegetable
{
public void Cook()
{
AddYou();
JiaRe();
FangCard();
ShouCai();
}
protected void AddYou()
{
Console.WriteLine("加油");
}
protected void JiaRe()
{
Console.WriteLine("加热");
}
protected abstract void FangCard();
protected void ShouCai()
{
Console.WriteLine("收菜");
}
}
public class ShengCai : CookVegetable
{
protected override void FangCard()
{
Console.WriteLine("放生菜");
}
}
public class CaiXin : CookVegetable
{
protected override void FangCard()
{
Console.WriteLine("放菜心");
}
}
internal class Program
{
private static void Main(string[] args)
{
CaiXin caixin = new CaiXin();
caixin.Cook();
ShengCai shengcai = new ShengCai();
shengcai.Cook();
/*
* 模板模式
*
* 模板模式就是利用继承实现需求
*
* 基类中封装好逻辑,子类只需要拓展重点的步骤过程
*
*/
Console.ReadKey();
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace _021模板模式
{
public abstract class CookVegetable
{
public void Cook()
{
AddYou();
JiaRe();
FangCard();
ShouCai();
}
protected void AddYou()
{
Console.WriteLine("加油");
}
protected void JiaRe()
{
Console.WriteLine("加热");
}
protected abstract void FangCard();
protected void ShouCai()
{
Console.WriteLine("收菜");
}
}
public class ShengCai : CookVegetable
{
protected override void FangCard()
{
Console.WriteLine("放生菜");
}
}
public class CaiXin : CookVegetable
{
protected override void FangCard()
{
Console.WriteLine("放菜心");
}
}
internal class Program
{
private static void Main(string[] args)
{
CaiXin caixin = new CaiXin();
caixin.Cook();
ShengCai shengcai = new ShengCai();
shengcai.Cook();
/*
* 模板模式
*
* 模板模式就是利用继承实现需求
*
* 基类中封装好逻辑,子类只需要拓展重点的步骤过程
*
*/
Console.ReadKey();
}
}
}