// The client code is usually suited to work with a single handler. In // most cases, it is not even aware that the handler is part of a chain. public static AbstractHandler SetUpAnimalFeedChain1() { // The other part of the client code constructs the actual chain. var monkey = new MonkeyHandler(); var squirrel = new SquirrelHandler(); var dog = new DogHandler(); monkey.SetNext(squirrel).SetNext(dog); return(monkey); }
static void Main(string[] args) { // The other part of the client code constructs the actual chain. var monkey = new MonkeyHandler(); var squirrel = new SquirrelHandler(); var dog = new DogHandler(); monkey.SetNext(squirrel).SetNext(dog); Console.WriteLine("Chain: Monkey > Squirrel > Dog\n"); Client.ClientCode(monkey); Console.WriteLine(); Console.WriteLine("Subchain: Squirrel > Dog\n"); Client.ClientCode(squirrel); }
static void Main(string[] args) { var monkey = new MonkeyHandler(); var squirrel = new SquirrelHandler(); var dog = new DogHandler(); monkey.SetNext(squirrel).SetNext(dog); //The client should be able to send a request to any handler, not just the first one in the chain. Console.WriteLine("Chain: Monkey > Squirrel > Dog\n"); Client.ClientCode(monkey); Console.WriteLine(); Console.WriteLine("Subchain: Squirrel > Dog\n"); Client.ClientCode(squirrel); }
static void Main(string[] args) { // Другая часть клиентского кода создает саму цепочку. var monkey = new MonkeyHandler(); var squirrel = new SquirrelHandler(); var dog = new DogHandler(); monkey.SetNext(squirrel).SetNext(dog); // Клиент должен иметь возможность отправлять запрос любому // обработчику, а не только первому в цепочке. Console.WriteLine("Chain: Monkey > Squirrel > Dog\n"); Client.ClientCode(monkey); Console.WriteLine(); Console.WriteLine("Subchain: Squirrel > Dog\n"); Client.ClientCode(squirrel); }
static void Main(string[] args) { var monkey = new MonkeyHandler(); var Squirrel = new SquirrelHandler(); var dog = new DogHandler(); monkey.SetNext(Squirrel).SetNext(dog); Console.WriteLine("Chain: Monkey>Squirrel>Dog \n"); Client.ClientCode(monkey); Console.WriteLine(); Console.WriteLine("Sub Chain: Squirrel> Dog \n"); Client.ClientCode(Squirrel); Console.ReadLine(); }