标签:
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();
}
}
}
标签:
原文地址:http://www.cnblogs.com/kexb/p/4525226.html