CampinCarl wrote:Well, mostly with trying to deal with class design/structure, class inheritance hierarchies, etc.. For instance, it doesn't seem like there is any existing language support for a generic interface class. How is that accomplished in CPP? Some sort of strange virtual class or something? Or not at all?
That one is easy. Don't need a book.
Because C++ does not really have features for a real interface, you just need a virtual destructor to make sure that this "class" gets cleaned up (you do need to declare the destructors virtual on any derived classes, especially when you have >2 levels of inheritance after the "interface").
class SomeInterface
{
virtual ~SomeInterface() {}
// methods
virtual void Foo(int someIndex) = 0;
virtual in Bar() = 0;
// you have to roll your own setter/getter
virtual void Enabled(const bool& flag) = 0;
virtual bool Enabled() = 0; // forgot offhand if you can declare this function const :P
};
class RealClass : public SomeOtherClass, public SomeInterface, public SomeOtherInterface
{
public:
RealClass() : _enabled(false) {}
virtual ~RealClass() {} // pretty much should declare your destructors virtual more often than not
// SomeInterface implementation
virtual void Foo(int someIndex) { /* ... */ }
virtual in Bar() { /* ... */ }
virtual void Enabled(const bool& flag) { _enabled = flag; }
virtual bool Enabled() { return _enabled; }
// implement other overrides and the virtual=0 functions
private:
bool _enabled; // store the property
};
If you want to stay pure OO, you just sort of follow the above. Now you can start "cheating" a little bit by refactoring implementations into some "intermediary" base class. Like in the above example, the "property" pretty much will be the same throughout your hierarchy, you can either use an intermediate derived class to put the implementation there, or just put into the "interface" class (the cheating part). A lot of people tend to put the prefix "I" in front of the class name to denote an interface, but the notation is somewhat religious that depends on who you talk to.
I think I start to see what you need.
C++ Coding Standards is what I recommend, but it covers more than the OO side of things, but (almost) all of C++. However, for class design/structure and inheritance hierarchies you should still use regular OO principles and design patterns. These concepts should remain more or less the same across languages.
Edit: PS: Coming from Java, you will need to read up on the RAII pattern (no one link I would recommend, go read up on what you can find from your favourite search engine), but it does not really have to do with high level OO.