home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / lang / cplus / 17860 < prev    next >
Encoding:
Text File  |  1992-12-12  |  3.4 KB  |  76 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!munnari.oz.au!metro!extro.ucc.su.OZ.AU!maxtal
  3. From: maxtal@extro.ucc.su.OZ.AU (John MAX Skaller)
  4. Subject: Re: Criticisms Wanted:Callbacks&Runtime methods
  5. Message-ID: <1992Dec12.154030.1342@ucc.su.OZ.AU>
  6. Keywords: callbacks C++ Runtime methods
  7. Sender: news@ucc.su.OZ.AU
  8. Nntp-Posting-Host: extro.ucc.su.oz.au
  9. Organization: MAXTAL P/L C/- University Computing Centre, Sydney
  10. References: <1gc6fhINN6nr@tamsun.tamu.edu>
  11. Date: Sat, 12 Dec 1992 15:40:30 GMT
  12. Lines: 62
  13.  
  14. In article <1gc6fhINN6nr@tamsun.tamu.edu> pinky@tamu.edu (The Man Behind The Curtain) writes:
  15. >
  16. >A few days ago, I posted asking how one could model calling a method
  17. >of an arbitary object without knowing whether or not that method
  18. >existed for that object.  Basically, I wanted to know if one could
  19. >have a runtime determination of an object's methods.
  20. >
  21. >But these capabilities are useful, and even necessary when you try
  22. >to model the real world.  For instance, might double click a key, and
  23. >then select from the screen any object to try to unlock with the key,
  24. >be it a bear, bush, or door.  These classes are mostly unrelated, but
  25. >in order to be able even attempt the operation, the base class of such
  26. >objects must at least have method for unlocking.  If objects can
  27. >interact in a wide variety of ways (a large number of verbs), then
  28. >the base class would contain an unweildy number of virtual functions.
  29.  
  30.     So put in all those methods! It is not expensive per object,
  31. only per class. I know exactly what you are talking about, having
  32. spent some months preparing a quote for a D&D game. There is
  33. a simple set of properties, but the objects all have different
  34. combinations of them. The interactions of different weapons,
  35. wielded by different characters against different classes of
  36. monsters is complex, and it cannot be easily generalised.
  37.  
  38.     One approach is to emulate the dynamism that C++ lacks.
  39. For while C++ is essentially static, it provides the low level
  40. tools to implement much more powerful systems.
  41.  
  42.     For example, you can suuply to each object a linked
  43. list of attributes: asking if an object has the attribute
  44. 'can be unlocked' is then simple to implement (scan the list
  45. for the attribute name 'unlockable'.
  46.  
  47.     The static alternative is to make all objects
  48. unlockable, except some have probability of sucess 0 with
  49. any key.
  50.  
  51.     The third approach is to use Smalltalk :-)
  52.  
  53. You will note that your problem cannot be solved 'properly' no matter
  54. what you do, since it requires nonexistant multimethods, that is, the effect
  55. of putting some key in some door cannot in general be computed
  56. with virtual functions: it depends on the exact type of the two objects.
  57. The only way to do it in general is with a very large lookup table.
  58. To avoid this, simplifiying assumptions are required: some general code
  59. and some special cases.
  60.  
  61.     For example, all swords work the same way, they just have
  62. different probabilities of hitting, penetration and damage.
  63. Multiplication and addition of numbers is the most general
  64. mechanism I can think of, along with a few special cases.
  65.  
  66.     (Whenever a Dragon Slayer is used on a Dragon, triple
  67. damage results and the dragon loses er fire for two rounds,
  68. provided the damage was to the head .... )
  69.  
  70.  
  71. -- 
  72. ;----------------------------------------------------------------------
  73.         JOHN (MAX) SKALLER,         maxtal@extro.ucc.su.oz.au
  74.     Maxtal Pty Ltd, 6 MacKay St ASHFIELD, NSW 2131, AUSTRALIA
  75. ;--------------- SCIENTIFIC AND ENGINEERING SOFTWARE ------------------
  76.