January 2019
Intermediate to advanced
512 pages
14h 5m
English
The tension between the two roles of a public virtual function, and the unnecessary exposure of the customization points created by such functions, lead us to the idea of making the implementation-specific virtual functions private. Herb Sutter in his article, Virtuality (http://www.gotw.ca/publications/mill18.htm), suggests that most, if not all, virtual functions should be private.
For the Template Method, moving virtual functions from public to private comes with no consequences (other than the initial shock of seeing a private virtual function, if you have never realized that C++ allows them):
class Base { public: bool TheAlgorithm() { if (!Step1()) return false; // Step 1 failed Step2(); return true; } private: