choosing between inheritance and compostion

when we are designing..when we have to give importance to inhertance and when to compostion..(compostion vs inheritance)..

please explain me with a code snippet :)

with regards,
vishnu k.
Use composition when you can and inheritance when you have to.

Use public inheritance if derived class can be used as-a base class. For example if it implements abstract interface or extends base class in some way.

There is also private/protected inheritance which is not often used. It is used if you need to inherit implementation but replace part of the implementation by your own functions (using virtual functions)
Topic archived. No new replies allowed.