Design Pattern Examples
Overview of object-oriented design patterns
c/HandlerChain_Exercise.h File Reference

Declaration of the HandlerChain_Exercise() function as used in the HandlerChain Pattern. More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define __HANDLERCHAIN_EXERCISE_H__
 

Functions

void HandlerChain_Exercise (void)
 Example of using the HandlerChain Pattern or Chain of Responsibility design pattern.
 

Detailed Description

Declaration of the HandlerChain_Exercise() function as used in the HandlerChain Pattern.

Definition in file c/HandlerChain_Exercise.h.

Macro Definition Documentation

◆ __HANDLERCHAIN_EXERCISE_H__

#define __HANDLERCHAIN_EXERCISE_H__

Definition at line 9 of file c/HandlerChain_Exercise.h.

Function Documentation

◆ HandlerChain_Exercise()

void HandlerChain_Exercise ( void  )

Example of using the HandlerChain Pattern 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 and the Handler Chain pattern is an object passed to handlers in a list.

In this exercise, multiple rectangular regions represented by the MessageWindow structure are represented by window IDs. The IDs are kept in a list to which messages can be passed, using the HandlerChain_SendMessage() function. That function iterates through the list of window IDs and calls MessageWindow_ProcessMessage() for each ID with the desired message. MessageWindow_ProcessMessage() passes control to one of several handler functions based on the type of the message.

Definition at line 88 of file HandlerChain_Exercise.c.

References _HandleChain_DestroyWindows(), _HandlerChain_ConstructWindowChain(), _ShowHandlerChain(), ButtonDown, ButtonUp, HandlerChain_SendMessage(), and Message_Initialize().