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

Represents a list of handlers that all implement the IMessageHandler interface. This list can be dynamically updated and each element in the list is passed messages for processing. More...

Collaboration diagram for HandlerChain:
Collaboration graph

Public Member Functions

void SendMessage (Message message)
 Send a message to each of the handlers in the list, protected by a multi-threading lock.
 
void AddHandler (IMessageHandler window)
 Add an instance of the IMessageHandler interface to end of the list of handlers, protected by a multi-threading lock.
 
void RemoveHandler (IMessageHandler window)
 Remove an instance of the IMessageHandler interface from the list, protected by a multi-threading lock.
 
override string ToString ()
 Convert this HandlerChain to a string, protected by a multi-threading lock.
 

Private Attributes

List< IMessageHandler_messageHandlers = new List<IMessageHandler>()
 The list of message handlers.
 
object _messageHandlersLock = new object()
 Object used to lock access to the message handlers list for multi-threaded support.
 

Detailed Description

Represents a list of handlers that all implement the IMessageHandler interface. This list can be dynamically updated and each element in the list is passed messages for processing.

Definition at line 55 of file HandlerChain_Class.cs.

Member Function Documentation

◆ AddHandler()

void AddHandler ( IMessageHandler  window)
inline

Add an instance of the IMessageHandler interface to end of the list of handlers, protected by a multi-threading lock.

If a message handler is already in the list, it is not added again.

Parameters
windowThe IMessageHandler object to add.

Definition at line 103 of file HandlerChain_Class.cs.

References HandlerChain._messageHandlers, HandlerChain._messageHandlersLock, and IMessageHandler.ID.

Referenced by MessageWindow.CreateWindow().

◆ RemoveHandler()

void RemoveHandler ( IMessageHandler  window)
inline

Remove an instance of the IMessageHandler interface from the list, protected by a multi-threading lock.

If the message handler is not in the list, the request to remove is ignored.

Parameters
window

Definition at line 124 of file HandlerChain_Class.cs.

References HandlerChain._messageHandlers, HandlerChain._messageHandlersLock, and IMessageHandler.ID.

Referenced by MessageWindow._HandleCloseMessage().

◆ SendMessage()

void SendMessage ( Message  message)
inline

Send a message to each of the handlers in the list, protected by a multi-threading lock.

Parameters
messageThe Message object to send to each handler.

Definition at line 74 of file HandlerChain_Class.cs.

References HandlerChain._messageHandlers, HandlerChain._messageHandlersLock, and IMessageHandler.ProcessMessage().

Referenced by MessageWindow._HandleButtonUpMessage(), and HandlerChain_Exercise.Run().

◆ ToString()

override string ToString ( )
inline

Convert this HandlerChain to a string, protected by a multi-threading lock.

Returns
Returns a string representation of this HandlerChain and all the handlers it contains.

Definition at line 143 of file HandlerChain_Class.cs.

References HandlerChain._messageHandlers, HandlerChain._messageHandlersLock, and IMessageHandler.ToString().

Member Data Documentation

◆ _messageHandlers

List<IMessageHandler> _messageHandlers = new List<IMessageHandler>()
private

◆ _messageHandlersLock

object _messageHandlersLock = new object()
private

Object used to lock access to the message handlers list for multi-threaded support.

Definition at line 66 of file HandlerChain_Class.cs.

Referenced by HandlerChain.AddHandler(), HandlerChain.RemoveHandler(), HandlerChain.SendMessage(), and HandlerChain.ToString().


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