Expand description
The HandlerChain design pattern example module
Example of using the “Handle Chain” or “Chain of Responsibility” design pattern.
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, while 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.
Accessed through the handlerchain_exercise() function.
Modules
- Contains the HandlerChain struct that manages all windows represented by the IMessageHandler trait.
- Contains the IMessageHandler trait.
- Contains the Message and MessagePosition structs, along with the MessageType enumeration, which are the foundation of the “Handler Chain” design pattern example.
- Contains the WindowRectangle struct and the MessageWindow struct.
Functions
- Helper method to construct a list of windows. Messages will be passed to these windows via the HandlerChain object.
- Example of using the “Handle Chain” or “Chain of Responsibility” design pattern.