Folks, I have a question on what should be the approach while designing a base class. My idea of a base class (until few days back) was to have as much code packed in it and then have minimal changes in the derived class. This way, the coding work in derived classes is less. But looking at some of the books on writing reusable code, I think this is not the correct method. Can someone give direction or point to article that discusses this? Regards,
Any code that's common to all classes would be best placed in the base class. Any code that's specific to a derived class would be best placed in that derived class. No derived class code should be present in the base class, and similarly no base class code should be present in the derived classes.
Thank you. Apart from what you said, it is also recommended that base class make no direct reference to concrete class even though such function might not belong to derived class. This way the base class does not have to change with every change to derived class.