Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   Base classes (http://www.go4expert.com/forums/base-classes-t23061/)

sharanbr 20Aug2010 20:38

Base classes
 
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,

xpi0t0s 22Aug2010 04:26

Re: Base classes
 
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.

sharanbr 22Aug2010 17:43

Re: Base classes
 
Quote:

Originally Posted by xpi0t0s (Post 71809)
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.


All times are GMT +5.5. The time now is 17:29.