Re: ABC question
Mehturt@gmail.com wrote:
This is more a design question I guess, sorry if it's off-topic..
I have found a post in the newsgroups where James Kanze says this on
'interfaces' in c++:
"That's only if you want to emmulate the weaknesses of Java. Normally,
in well written C++, you don't make virtual functions public. An
interface will contain public functions (often inline) which forward
to private pure virtual functions. Wrapping the call in the various
pre- and post-condition checks, tracing and logging, etc. "
Just a reminder: normally doesn't mean always:-). There are
cases (inversion of control, etc.) where there is no contract,
and where it might not be applicable.
Why is this true? I mean why introduce one more level of
nesting in the interface class? Is it only for logging /
checking purposes?
I'm not sure why the "only". The base class defines the
contract, and contains the code to enforce it. And the derived
class shouldn't be able to change it. This means that the
function the user sees cannot be virtual, since the user
invocation must pass through the base class. (Note that some
languages have automatic support for this---you specify the
contract, and the compiler generates the two functions,
transparently.)
--
James Kanze GABI Software
Conseils en informatique orient?e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S?mard, 78210 St.-Cyr-l'?cole, France, +33 (0)1 30 23 00 34
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]