Summary

In this chapter, we have studied, extensively, the applications of the Strategy pattern (also known as the policy pattern) to C++ generic programming. The combination of the two gives rise to one of the most powerful tools in the arsenal of a C++ programmer—the policy-based design of classes. This approach provides great flexibility by allowing us to compose the behavior of the class from many building blocks, or policies, each of which is responsible for a particular aspect of the behavior. 

We have learned different ways to implement policies—these can be templates, classes with template member functions, classes with static functions, and even classes with constant values. Just as varied are the ways that we can use policies through composition, inheritance, or direct access to static members. Policy parameters can be types or templates, each with their own advantages and limitations.

A tool as powerful as policy-based design is also easily misused or applied in poor judgment. Often, such situations arise from the gradual evolution of the software toward more and more complexity. To mitigate such mischance, we have provided a set of guidelines and recommendations that focus on the key advantages that the policy-based design offers to the programmer and suggested the techniques and constraints that maximize such advantages.  

We have also considered a more limited design pattern that can sometimes be used to mimic the policy-based approach, without some of its drawbacks. Yet more such limited alternatives will be described in Chapter 17, Adapters and Decorators. This chapter is dedicated to the Decorator pattern and the more general Adapter pattern. Both are sort of C++ magic tricks—they make an object appear as something it's not.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.187.79