PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.cplus > Composition vs. Inheritance
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Composition vs. Inheritance

Réponse
 
LinkBack Outils de la discussion
Vieux 03/06/2008, 18h40   #1
Pallav singh
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Composition vs. Inheritance

Hi All

i have dout when to use Composition and Inheritance while designing
Module in C++

Thanks
Pallav
  Réponse avec citation
Vieux 03/06/2008, 18h48   #2
Victor Bazarov
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Composition vs. Inheritance

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
  Réponse avec citation
Vieux 03/06/2008, 20h25   #3
Juha Nieminen
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Composition vs. Inheritance

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'."
  Réponse avec citation
Vieux 04/06/2008, 07h45   #4
sumsin
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Composition vs. Inheritance

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’.
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 13h45.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,13526 seconds with 12 queries