Home > Articles > Programming > C/C++

  • Print
  • + Share This
Like this article? We recommend


The strategy pattern helps to avoid large numbers of if-else statements in classes. Instead, each class or subclass can define its own strategy method. I used the chain of responsibility pattern as a backdrop for illustrating the strategy pattern. One limitation of the chain of responsibility occurs when no handler is configured for the problem. In this case, the event might not be handled by any object.

It’s likely that an implementation of the strategy pattern in this context would require a managed object to handle more than a single event. More details about the patterns used in this article can be found in [3] in the "Additional Reading" section.

To run the supplied code (see [4] in the "Additional Reading" section), create a Visual C++ solution (using existing code) and drop in the two source code files: EventHandler.cpp and EventHandler.h.

  • + Share This
  • 🔖 Save To Your Account