|
|
|
#1 |
|
Messages: n/a
Hébergeur: |
Hi All
i have dout when to use Composition and Inheritance while designing Module in C++ Thanks Pallav |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
Pallav singh wrote:
> i have dout when to use Composition and Inheritance while designing > Module in C++ If you mean private inheritance, then the conversion from the class to the one it inherits from will still be available to the class and its friends, so I'd stick with composition. V -- Please remove capital 'A's when replying by e-mail I do not respond to top-posted replies, please don't ask |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
Pallav singh wrote:
> 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'." |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
On Jun 3, 10:40 pm, Pallav singh <singh.pal...@gmail.com> wrote:
> Hi All > > i have dout when to use Composition and Inheritance while designing > Module in C++ > > Thanks > Pallav First of all try to find out the various entities in your design. Then for a group of similar entities try to generalize them, as Juha said for various kind of buttons like Radio-Button and Push-Button, it is possible to generalize them with a button class. So here you should use inheritance, where Button would the generic class for Radio-Button and Push-Button. While in case of composition you should think about the ingredient of the entity. As Juha said, in general most of the Dialog Boxes have ‘Ok’ and ‘Cancel’ buttons. So here you should use composition, where your Dialog box is composed of with two Push-Buttons ‘Ok’ and ‘Cancel’. |
|
![]() |
| Outils de la discussion | |
|
|