home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / cplus / 16781 < prev    next >
Encoding:
Internet Message Format  |  1992-11-23  |  2.8 KB

  1. Path: sparky!uunet!pcad!johns
  2. From: johns@pcad.UUCP (John Storey)
  3. Newsgroups: comp.lang.c++
  4. Subject: Beginner OOD question
  5. Keywords: OOD dungeon interface
  6. Message-ID: <625@pcad.UUCP>
  7. Date: 23 Nov 92 18:33:29 GMT
  8. Organization: Personal CAD Systems, Westford, MA
  9. Lines: 44
  10.  
  11. Just learning C++ (and MS-Windows, as an aside).  I was putting together a test program
  12. for the following two classes: STICON and STBITMAP, which basically are just encapsulating
  13. some functionality for manipulating icons and bitmaps on a Microsoft Windows window.
  14.  
  15. So I decided the classic hero and monster in a dungeons would work nicely, and came up 
  16. with the following classes:
  17.  
  18.     Dungeon ('has a' hero, a monster (as icons) and walls and corridors (as bitmaps))
  19.     Hero
  20.     Monster
  21.     VIO (basically, I want to hide the MS-Windows specific stuff - handles to windows,
  22.         etc., from the first three classes, so I figured that I could have them
  23.         communicate their information to VIO who would take care of it -
  24.         so Hero would say to Dungeon "Move me north one space" and if that
  25.         was ok Dungeon would say to VIO "Draw a corridor at (x,y)" which is
  26.         Hero's previous position, and then tell Hero "Draw yourself at (x,y)"
  27.         causing Hero to tell VIO "Draw Hero at (x,y)"
  28.  
  29.     
  30. My problem with all this, is that the Hero and the Dungeon know all about each other.  So I wanted
  31. to separate them.  This led me to recreating (so I'm told) the Smalltalk interface - I had everyone
  32. have a common ancestor object UMC (Universal Message Center) which allowed them to send messages to
  33. each other - at the same time learning how to use static data members, Borland's Templates, and
  34. the importance of virtual destructors, so even though is the wrong approach I at least learned alot.
  35.  
  36. So, does anyone have any suggestions as to how to best keep the Dugeon and Hero separate here?  I've
  37. been thinking that another class which keeps the position of all moveable objects in the dungeon stored,
  38. which makes replacing one Dungeon with another easy, but it seems like now that both the Dungeon and
  39. Hero class still have a pretty high degree of coupling, just now with the new class instead of each other.
  40.  
  41. My other problem here is that there is no reason for my original two classes (STICON and STBITMAP
  42. ) to be known about by anyone other that the VIO class, so I have to have the Hero class and
  43. the VIO class would contain an STICON corressponding to the Hero.  This actually strikes me as the
  44. correct approach, but it's seems needlessly complicated to have two classes representing the
  45. same icon on the screen.
  46.  
  47. Sorry if I'm a bit unclear hear - I really explain things much better with a whiteboard so I can
  48. draw the class interactions as I talk, and truth to tell some points are muddled in my mind as well
  49. (else I wouldn't need to post, eh?)
  50.  
  51. Thanks in advance,
  52. John Storey
  53. mail to: uunet!pcad.odin!johns
  54.  
  55.