Csharp/CSharp Tutorial/Design Patterns/Template Pattern

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

Template Method Pattern

using System;
  public abstract class Window
  {
    public abstract void  PositionLabel();
      
    public void SetupWindowFace()
    {
      this.PositionLabel();
    }
    public Window(){;}
    
  }
  public class WindowDeluxe: Window
  {
    public override void  PositionLabel()
    {Console.WriteLine("center.");}
    
    public WindowDeluxe(){;}
  }
  public class WindowStandard:Window
  {
    public override void PositionLabel(){;}
    public WindowStandard()  {;}
    
  }
  class Client
  {
    static void Main(string[] args)
    {
      Window delWindow = new WindowDeluxe();
      delWindow.SetupWindowFace();
      Window stdWindow = new WindowStandard();
      stdWindow.SetupWindowFace();
    }
  }