Template Method Pattern : Template Pattern « Design Patterns « C# / C Sharp






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();
    }
}

 








Related examples in the same category