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

职责链模式c#(处理车)

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

标签:

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

namespace 职责链模式
{
    public interface ICarHandler
    {
        ICarHandler next { get; set; }
        ICarHandler setNextCanHandler(ICarHandler handler);
        void HandlerCar();
    }

    public class ACarHander : ICarHandler
    {
      
        public ICarHandler next { get; set; }

        public ICarHandler setNextCanHandler(ICarHandler handler)
        {
            this.next = handler;
            return this.next;
        }

        public void HandlerCar()
        {
            Console.WriteLine("处理车头");
            this.next.HandlerCar();
        }
    }
    public class BCarHander : ICarHandler
    {

        public ICarHandler next { get; set; }

        public ICarHandler setNextCanHandler(ICarHandler handler)
        {
            this.next = handler;
            return this.next;
        }

        public void HandlerCar()
        {
            Console.WriteLine("处理车身");
            this.next.HandlerCar();
        }
    }
    public class CCarHander : ICarHandler
    {

        public ICarHandler next { get; set; }

        public ICarHandler setNextCanHandler(ICarHandler handler)
        {
            this.next = handler;
            return this.next;
        }

        public void HandlerCar()
        {
            Console.WriteLine("处理车尾");
            this.next.HandlerCar();
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            ICarHandler c1=new ACarHander();
            ICarHandler c2=new BCarHander();
            ICarHandler c3=new CCarHander();
            c1.setNextCanHandler(c2).setNextCanHandler(c3);
            c1.HandlerCar();
            Console.ReadKey();
        }
    }
}

职责链模式c#(处理车)

标签:

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

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