Lars Gullik Bj?nnes wrote: >>> | I always though the point about NVI is that you can add >>> | pre-processing/post-processing before calling the virtual function. At >>> | least that what I've heard -- I never needed to add such pre/post >>> | processing. >>> >>> That is also an argument. If you look at dispatch/doDispatch in >>> InsetBase you see that we use this. >> > | BTW, I also believe NVI is not necessary for pure virtual functions > | (like 'clone' in insetbase.h). They are really part of the interface. > > NVI is being used by the C++ Standard library (look at the iostreams), > and touted as "best practice", not only by Herb Sutter, but also by > Scott Meyers. It is not like Herb Sutter has conjured this out of thin > air.
Just for reference: item 39 in "C++ Coding standards" by Herb Sutter and Alexandrescu (just published) talks about the same. The advantages they give are pre/post processing, more stable base classes (if you need to add preprocessing, you don't need to go renaming a method in all derived classes, and ability to have something smarter that 1<->1 mapping between public and private methods. This all sounds resonable, but whether this justifies applying NVI to very small methods like accessors and 'clone' is up to you. I don't (yet?) think so. Just wanted to share some thoughts... - Volodya