I think that what Alexandrescu talks about in the Mechanics section is outlined in the rest of the chapter. He refers to how much more flexible design based on policy is based on design of classes based on inheritance, especially in relation to different ways of implementing and combining policies - this is compared to a single implementation and combination allowed through multiple inheritance.
For example, when discussing Creator policies, he indicates that the policy requires only the Create () method, which returns a pointer to the class to be created, but does not indicate that it is virtual or non-static. And it shows several ways to create each policy: a simple policy class, such as (from section 1.5, skipping MallocCreator and PrototypeCreator policies)
template<class T> struct OpNewCreator { static T* Create() { return new T; } };
...
> //Library code > template <class CreationPolicy> > class WidgetManager:public CreationPolicy > { > ... > };
...
or it can be implemented with template template parameters (section 1.5.1) as
//Library Code template <template <class> class Creation Policy> class WidgetManager : public CreationPolicy <Widget> { ... } // Application Code typedef WidgetManager<OpNewCreator> MyWidgetMgr
or (section 1.5.2) - implemented as a member function of the template:
struct OpNewCreator { template <class T> static T* Create() { return new T; }
}
These are examples of flexible mechanics that are available in a template-based policy class solution and are not available in a multiple inheritance solution. These specific examples may not be all that are interesting, perhaps because they should be short and simple for pedagogical reasons.
Breandán dalton
source share