Design Pattern Examples
Overview of object-oriented design patterns
HandlerChain_Exercise Class Reference

Example of using the HandlerChain Pattern or Chain of Responsibility pattern in C#. More...

Collaboration diagram for HandlerChain_Exercise:
Collaboration graph

Public Member Functions

void Run ()
 Executes the example for the HandlerChain Pattern in C#.
 

Private Member Functions

void _HandlerChain_ConstructWindowChain (HandlerChain handlerChain)
 Helper method to construct a list of windows. Messages will be passed to these windows via the HandlerChain object.
 

Detailed Description

Example of using the HandlerChain Pattern or Chain of Responsibility pattern in C#.

The Handler Chain pattern is used to support a dynamic list of handlers that are passed the same arguments. It is kind of the inverse of the Visitor pattern, where the Visitor pattern is a handler that is passed to all objects in a list and the Handler Chain pattern is an object passed to handlers in a list.

In this exercise, multiple rectangular regions called MessageWindows embody the handlers and the HandlerChain object passes message objects to each MessageWindow until the message is handled.

Definition at line 29 of file HandlerChain_Exercise.cs.

Member Function Documentation

◆ _HandlerChain_ConstructWindowChain()

void _HandlerChain_ConstructWindowChain ( HandlerChain  handlerChain)
inlineprivate

Helper method to construct a list of windows. Messages will be passed to these windows via the HandlerChain object.

Parameters
handlerChainThe HandlerChain object that receives the new windows.

Definition at line 37 of file HandlerChain_Exercise.cs.

References MessageWindow.CreateWindow().

Referenced by HandlerChain_Exercise.Run().

◆ Run()

void Run ( )
inline

Executes the example for the HandlerChain Pattern in C#.

Definition at line 53 of file HandlerChain_Exercise.cs.

References HandlerChain_Exercise._HandlerChain_ConstructWindowChain(), and HandlerChain.SendMessage().

Referenced by Program.Run().


The documentation for this class was generated from the following file: