-
Designing Classes
When you come to a business application, and you will be involved with a lot of classes and objects etc. Is best to design a base class with most of the functionality you intend to use, and then create an instance of that class. Or is better to make a class modular, i.e. using inheritance instead of putting quite a lot of code in one main class. The reason I’m asking is because I can see the modular approach to be more readable and maintainable, on the other hand you have the extra processing offset of calling the constructors from each class, and initialising them appropriately. If you are creating quite a lot of objects from an inherited class, this could cause quite a strain on processing power.
-
The real idea behind inheritance is polymorphism. If classes have no virtual functions they are probably not made to be inherited from although in some situations this is a conveinience it is generally not recommended.
With this in mind you should try to make your base classes specify a generic interface with little or better still no implementation. The implementations of the pure virtual functions are in the derived classes.This is abstract class design.The concrete classes do all the work and the abstract classes offer the public interface.
-
I agree with stoned-coder. The greatest benefit of deriving all objects from a single class is that you can quickly store pointers of completely unrelated classes within eachother, if needed, as well as for other debugging and special application purposes. Other than that, from there it should completely modular, inherited code which of course makes maintainance very easy. But as far as virtual functions, other than the more obvious ones, there is little value in using them very far down the heirarchy, reserving their use for less ambiguous roles.