home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / lang / cplus / 16153 < prev    next >
Encoding:
Internet Message Format  |  1992-11-12  |  2.5 KB

  1. Path: sparky!uunet!airgun!airgun.wg.waii.com!bab
  2. From: bab@se39.wg2.waii.com (Brian Button)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Discriminating Variant Records Without switch() ??
  5. Message-ID: <BAB.92Nov12074430@se39.wg2.waii.com>
  6. Date: 12 Nov 92 12:44:30 GMT
  7. References: <BAB.92Nov10073324@se39.wg2.waii.com> <1992Nov11.144253.26415@bnr.ca>
  8. Sender: news@airgun.wg.waii.com
  9. Organization: Western Geophysical Exploration Products
  10. Lines: 37
  11. Nntp-Posting-Host: se39.wg2.waii.com
  12. In-reply-to: holiday@bnr.ca's message of 11 Nov 92 14:42:53 GMT
  13.  
  14.  
  15. In article <BAB.92Nov10073324@se39.wg2.waii.com>, bab@se39.wg2.waii.com (Brian Button) writes:
  16. |> Is there a simple, OOP based way to discriminate between variant
  17. |> records? I saw an article in C Users Journal last month titled "Switch
  18. |> Deemed Harmful to C++" or something like that, but I couldn't figure
  19. |> out how to do it any other way.
  20.  
  21.  
  22. ->"Matthew" == Matthew Holiday <holiday@bnr.ca> writes:
  23.    Matthew> switch statement! :-) There ought to be a convenient way
  24.    Matthew> to create objects from network messages, i.e., some way to
  25.    Matthew> register message types and their matching class types,
  26.    Matthew> such that for every incoming message, its body (an array
  27.    Matthew> of bytes) gets turned into the correct object, which would
  28.    Matthew> be derived from a root generic message object.
  29.  
  30. There is such a way using factory classes such as the RogueWave
  31. RWFactory class. The problem I'm having is figuring out how to deal
  32. with these objects after they are already created. Since there's no
  33. common set of operations which are performed on each of the objects,
  34. there is no set of methods which may be made virtual and overloaded.
  35. Herein lies the problem. This seems to point towards using special
  36. purpose code for each class, which would necessitate using a switch.
  37.  
  38. Have I painted myself into a corner or is there some way out. How are
  39. the rest of you OOP programmers dealing with cases like this?
  40.  
  41. bab
  42.  
  43. --
  44. |-----------------------|----------------------------------------------------|
  45. | Brian Button          | email : button@wg2.waii.com                        |
  46. | Design Engineer       |         71023.276@compuserve.com                   |
  47. | Western Geophysical   | voice : (713)964-6221                              |
  48. | 3600 Briarpark        |----------------------------------------------------|
  49. | Houston, Texas  77042 |                  Opinions Be Mine!!                |
  50. |-----------------------|----------------------------------------------------|
  51.