From: Stefan S. <ste...@or...> - 2003-01-31 16:12:51
|
hi there, Murray asked me to drag some points we were discussing on the patch manager into this list... We were discussing some code styling issues, and I'd like to raise these points again here: 1) I suggest to use 'using namespace xmlpp;' inside .cc files, as that is more restrictive. It means that the compiler will not put any additional symbols *declared* in the .cc file into the xmlpp namespace, but only associate *definitions* with declarations from the headers. I prefer that because it's more explicit. (Specifically, when you explicitely want to hide symbols, put them into anonymous namespaces) 2) 'using foomethod;' in derived class declaration: Murray suggests people may not be familiar with that concept. The goal of this shortcut is to drag base class methods into the derived class. A more lengthy way would be to write 'foomethod() { BaseClass::foomethod();} That's relevant in two situations: a) the base method declares the method in question as being protected, while the derived class wants to expose it publicly. b) the derived class overrides the method by a method with the same name, but a different signature. Example: the base class has 'void foo();', and the derived class defines 'void foo(int);'. This would hide the original 'void foo();' method, so if you want to expose both, you have to redeclare (via 'using') or redefine it. 3) hiding state in the private section: It's a matter of good encapsulation to put all members into the private section, and then provide accessors (either public or protected). That helps to decouple dependencies between base and derived classes. Of course, derived classes then can't access the member variable. That's exactly the point, that's the goal ! Comments and criticism are appreciated... Stefan |