Pallav said:
i have dout when to use Composition and Inheritance while designing
Module in C++
Rule of thumb: Can you say that "<derived class> is a <base class>"?
If yes, then maybe inheritance will work.
Moreover, the <base class> should usually be more abstract as a
concept than <derived class>, which should be a more concrete concept.
Example: Base class is a "widget" and derived class is a "button". You
can say "a 'button' is a 'widget'". A "widget" is a more abstract
concept because there are many things which can "be a widget", while
"button" is a more concrete concept because not so many things can "be a
button".
Example: A "dialog" class has two "button" widgets. You cannot say "a
'dialog' is a 'button'", ergo composition. "A 'dialog' has a 'button'."