码迷,mamicode.com
首页 > Windows程序 > 详细

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

时间:2015-05-24 06:29:04      阅读:143      评论:0      收藏:0      [点我收藏+]

标签:

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

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

标签:

原文地址:http://www.cnblogs.com/kexb/p/4525244.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!