home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / lang / cplus / 12735 < prev    next >
Encoding:
Internet Message Format  |  1992-08-21  |  2.0 KB

  1. Path: sparky!uunet!lhdsy1!kato.lahabra.chevron.com!hwrvo
  2. From: hwrvo@kato.lahabra.chevron.com (W.R. Volz)
  3. Newsgroups: comp.lang.c++
  4. Subject: OOD and Inheritance question
  5. Message-ID: <6298@lhdsy1.lahabra.chevron.com>
  6. Date: 21 Aug 92 17:28:58 GMT
  7. Sender: news@lhdsy1.lahabra.chevron.com
  8. Organization: Chevron Oil Field Research Company
  9. Lines: 42
  10.  
  11. I have a question on how to design a set of classes. It probably has a really
  12. simple answer. But here goes anyway:
  13.  
  14. Let's say I have a class called Card (A playing card).
  15. A collection of Cards is a CardPile. So this implies maybe a linked list.
  16.  
  17. Question 1: How should CardPile have the link installed: inherited or member
  18. data? A link is not a Card so maybe it should be a data member. On the other
  19. hand, I can create a new entity of CardPile by inheriting from both
  20. Card and Link. (similar to inheriting from class Boy and class Scout to
  21. make a new class BoyScout.) What would be best or does it depend a lot of 
  22. how I'm going to use CardPile? 
  23.  
  24. Question 2: I might want to add member functions that draw the card to make
  25. a new class of CardView. Should this inherit from Card or CardPile. Or should
  26. CardPile inherit from CardView which inherits from Card?
  27.  
  28.      A                              B
  29. class Card                     class Card
  30. class CardPile : Card      or  class CardView Card
  31. class CardView : CardPile      class CardPile : CardView
  32.  
  33. In A, I can have a pile of cards or a visible pile of cards. But the drawing
  34. functionality for drawing a card should probably not be inheriter from CardPile,
  35. but should be inherited as in B. But in B, I can't just have a pile of card
  36. without visibility functions. It seems that this would be a good place for
  37. templates:
  38.  
  39. class Card
  40. class CardView
  41. class CardPile <T>
  42.  
  43. I seem to have just answered my own question here. But anyother opinions?
  44.  
  45. -- 
  46.  
  47. ======================
  48. Bill Volz
  49. Chevron Oil Field Research Co.
  50. Exploration Research/Geophysics Division.
  51. P.O. Box 446, La Habra, CA 90633-0446
  52. Phone: (310) 694-9340
  53.