Dr. Dobb's is part of the Informa Tech Division of Informa PLC

This site is operated by a business or businesses owned by Informa PLC and all copyright resides with them. Informa PLC's registered office is 5 Howick Place, London SW1P 1WG. Registered in England and Wales. Number 8860726.


Channels ▼
RSS

C/C++

The C++ Chain of Responsibility Pattern and Network Events


Conclusion

The chain of responsibility pattern provides an interesting technique for equipping related objects with more intelligence. This allows for a concomitant reduction in the intelligence of a central event handler. This avoids heavy-duty monolithic servers that process all event messages and call remote objects. Instead, the remote objects themselves (such as LSPs) can provide their own handlers for messages. The overhead for doing this is pretty light—a successor variable is required along with an event holder. In addition to this, we would need a message dispatcher to get the chain going.

Some of the tradeoffs for the chain of responsibility pattern include:

  • The need to explicitly define event types in the objects risks cluttering our class definitions. However, events have to be defined anyway even if we use a central event handler. Placing event definitions in the classes is often more meaningful than putting them in a central location
  • Chain of responsibility may lose messages if no handler is found, so it's important to have a default event handler

An advantage is that objects are equipped with event handlers for only those events that matter to them. This allows for a more real world lightly coupled object model. To find out more about the chain of responsibility pattern, please see [2].

In keeping with the magic of design patterns, the main point I'd like you to take away is that the chain of responsibility provides a lot of power with very little code—in this case just two source code files: EventHandler.cpp and EventHandler.h!

Get the source code for this article.

Additional Reading

[1] "Network Management, MIBs & MPLS: Principles, Design & Implementation" by Stephen Morris - includes strategies for IT folks to avoid being offshored

[2] "Design Patterns: Elements of Reusable Object-Oriented Software" by Erich Gamma, Richard Helm, Ralph Johnson, John Vlissides, 1995, Addison-Wesley


Related Reading


More Insights






Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

 
Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.