模板模式c#(非常简单,但又非常简洁好玩)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace 模板模式
{
    public abstract class CarProces
    {
        public abstract void handler1();
        public abstract void handler2();

public void handler()
        {
            handler1();
            handler2();
        }
    }

public class BusProcess : CarProces
    {
        public override void handler1()
        {
            Console.WriteLine("car process1");
        }

public override void handler2()
        {
            Console.WriteLine("car process2");
        }
    }
    public class JeepProcess : CarProces
    {
        public override void handler1()
        {
            Console.WriteLine("jeep process1");
        }

public override void handler2()
        {
            Console.WriteLine("jeep process2");
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            CarProces c1=new BusProcess();

CarProces c2=new JeepProcess();
           c1.handler();
            Console.WriteLine("--------------------");
            c2.handler();
            Console.ReadKey();
        }
    }
}

上一篇:tachyon with spark


下一篇:判断浏览器是pc端还是手机端