Csharp/C Sharp/Design Patterns/Template Pattern

Материал из .Net Framework эксперт
Перейти к: навигация, поиск

Template Method Pattern

 
using System;
public abstract class Calculate {
    public abstract void PositionLabel();
    public void SetupCalculate() {
        this.PositionLabel();
    }
    public Calculate() {}
}
public class CalculateDeluxe : Calculate {
    public override void PositionLabel() {
        Console.WriteLine("Deluxe clock");
    }
    public CalculateDeluxe() { ;}
}
public class CalculateStandard : Calculate {
    public override void PositionLabel() {}
    public CalculateStandard() {}
}
class Client {
    static void Main(string[] args) {
        Calculate delCalculate = new CalculateDeluxe();
        delCalculate.SetupCalculate();
        Calculate stdCalculate = new CalculateStandard();
        stdCalculate.SetupCalculate();
    }
}