using System;
using System.Collections.Generic;
namespace TestCS
{
class Program
{
// template pattern
static void Main(string[] args)
{
Vehicle vehicle0 = new Maserati();
vehicle0.Launch();
vehicle0.Brake();
Vehicle vehicle1 = new BMW();
vehicle1.Launch();
vehicle1.Brake();
Console.ReadKey();
}
// template
abstract class Vehicle
{
public abstract void Launch();
public abstract void Brake();
}
class Maserati : Vehicle
{
public override void Brake()
{
Console.WriteLine("Maserati Brake");
}
public override void Launch()
{
Console.WriteLine("Maserati Launch");
}
}
class BMW : Vehicle
{
public override void Brake()
{
Console.WriteLine("BMW Brake");
}
public override void Launch()
{
Console.WriteLine("BMW Launch");
}
}
}
}
C#设计模式-模板模式
猜你喜欢
转载自blog.csdn.net/qq_37273889/article/details/85040631
今日推荐
周排行