Re: Ok --- *enough* with the private virtual functions...
Pete Becker wrote:
Carlos Moreno wrote:
Help? Please? Maybe one concrete example (as in, not class B and
class D) that shows how private virtual functions help?
One abstract example <g>: in the public function you can validate
arguments, then call the virtual function. Overriders in derived classes
don't have to duplicate the validation. More generally, any general
massaging of arguments or of the result can be done in the public function.
Exactly so, to which I'll add - sequencing enforcements (you can only
call some functions in certain states) etc. The basic view of the world
is that in a well-designed hierarchy, the high-level operations are the
same, and the differences stand in details defined in lower-level
functions. The lower-level functions shouldn't be necessarily accessible
directly, but instead through the higher-level functions. This
philosophy is in keep with the (correct IMHO) perception that
inheritance is best at modeling entities with much similarity and little
variation.
The sad part is that discipline is still required - a derived class can
republicize a private virtual function. Also, a derived class can
"override" a nonvirtual base class' function, with the well-known
confusing outcome.
Andrei
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]