home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!lhdsy1!kato.lahabra.chevron.com!hwrvo
- From: hwrvo@kato.lahabra.chevron.com (W.R. Volz)
- Newsgroups: comp.lang.c++
- Subject: OOD and Inheritance question
- Message-ID: <6298@lhdsy1.lahabra.chevron.com>
- Date: 21 Aug 92 17:28:58 GMT
- Sender: news@lhdsy1.lahabra.chevron.com
- Organization: Chevron Oil Field Research Company
- Lines: 42
-
- I have a question on how to design a set of classes. It probably has a really
- simple answer. But here goes anyway:
-
- Let's say I have a class called Card (A playing card).
- A collection of Cards is a CardPile. So this implies maybe a linked list.
-
- Question 1: How should CardPile have the link installed: inherited or member
- data? A link is not a Card so maybe it should be a data member. On the other
- hand, I can create a new entity of CardPile by inheriting from both
- Card and Link. (similar to inheriting from class Boy and class Scout to
- make a new class BoyScout.) What would be best or does it depend a lot of
- how I'm going to use CardPile?
-
- Question 2: I might want to add member functions that draw the card to make
- a new class of CardView. Should this inherit from Card or CardPile. Or should
- CardPile inherit from CardView which inherits from Card?
-
- A B
- class Card class Card
- class CardPile : Card or class CardView Card
- class CardView : CardPile class CardPile : CardView
-
- In A, I can have a pile of cards or a visible pile of cards. But the drawing
- functionality for drawing a card should probably not be inheriter from CardPile,
- but should be inherited as in B. But in B, I can't just have a pile of card
- without visibility functions. It seems that this would be a good place for
- templates:
-
- class Card
- class CardView
- class CardPile <T>
-
- I seem to have just answered my own question here. But anyother opinions?
-
- --
-
- ======================
- Bill Volz
- Chevron Oil Field Research Co.
- Exploration Research/Geophysics Division.
- P.O. Box 446, La Habra, CA 90633-0446
- Phone: (310) 694-9340
-