7using System.Collections.Generic;
10using System.Threading.Tasks;
56 Console.WriteLine(
"Handler Chain Exercise");
63 Console.WriteLine(
" Handler Chain at start:");
64 Console.WriteLine(handlerChain);
68 Console.WriteLine(
" Select Window 2");
71 Console.WriteLine(
" Current handler chain:");
72 Console.WriteLine(handlerChain);
74 Console.WriteLine(
" Select Window 3");
77 Console.WriteLine(
" Current handler chain:");
78 Console.WriteLine(handlerChain);
80 Console.WriteLine(
" Select Window 1");
83 Console.WriteLine(
" Current handler chain:");
84 Console.WriteLine(handlerChain);
86 Console.WriteLine(
" Close Window 2");
89 Console.WriteLine(
" Current handler chain:");
90 Console.WriteLine(handlerChain);
92 Console.WriteLine(
" Done.");
Example of using the HandlerChain Pattern or Chain of Responsibility pattern in C#.
void _HandlerChain_ConstructWindowChain(HandlerChain handlerChain)
Helper method to construct a list of windows. Messages will be passed to these windows via the Handle...
void Run()
Executes the example for the HandlerChain Pattern in C#.
Represents a list of handlers that all implement the IMessageHandler interface. This list can be dyna...
void SendMessage(Message message)
Send a message to each of the handlers in the list, protected by a multi-threading lock.
Represents a rectangular region that can handle messages directed to that region.
static MessageWindow CreateWindow(string title, int x, int y, int width, int height, HandlerChain handlerChain)
Creates an instance of the MessageWindow class with the specified attributes and adds the new instanc...
The namespace containing all Design Pattern Examples implemented in C#.
MessageType
Type of message handled by MessageWindow.
Represents a message sent to the windows. A message contains a type and a position.
Position of the message in global coordinates (same scope of coordinates as windows)....