home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / sys / next / programm / 5603 < prev    next >
Encoding:
Text File  |  1992-08-13  |  2.2 KB  |  65 lines

  1. Newsgroups: comp.sys.next.programmer
  2. Path: sparky!uunet!munnari.oz.au!bruce.cs.monash.edu.au!monu6!ede978e
  3. From: ede978e@monu6.cc.monash.edu.au (Robert D. Nicholson)
  4. Subject: Re: lots of objects to display
  5. Message-ID: <1992Aug14.070249.13214@monu6.cc.monash.edu.au>
  6. Organization: Monash University, Caulfield Campus
  7. References: <1992Aug13.204505.26009@ornl.gov>
  8. Date: Fri, 14 Aug 1992 07:02:49 GMT
  9. Lines: 54
  10.  
  11. woo@ornl.gov(John W. Wooten) writes:
  12.  
  13. >I have an app in which I have a lot of elements, which may have
  14. >many different geometrical shapes, but are subclassed from a general  
  15. >element object which is a subclass of View.  As I build them, they are  
  16. >stored in a list.
  17.  
  18. >I want them to be drawn in a View (myView) in myWindow.  Each element   
  19. >subclass has a drawSelf method and each instance has it, of course.
  20.  
  21. >When my controller does a [myView display], the background appears, but  
  22. >does each element have to be individually sent a [myElement drawSelf]?
  23. >It then seems that they each have to be a subView of the original View.
  24.  
  25. >Somehow it should be simpler than this, so I think I'm missing  
  26. >something.
  27.  
  28.  
  29.  
  30. >--
  31. >-----------------
  32. >J. W. Wooten
  33.  
  34. Well, {myView display] will only send display to myView and myView's subviews
  35. which have been set up via view's addSubview.  Thus you should create a 
  36. allGraphicsPerform method  and have it send a display to each element in the list.
  37. Actually you can pass the method you wish to have executed as a parameter and
  38. thus generalise even further.
  39.  
  40. Check out Summer NeXTWORLD , 1992 in Charles L. Perkins Article on Composition
  41. makeSquaresPerform:
  42.  
  43. The code looks like 
  44.  
  45. - makeSquaresPerform:(SEL) aMessage {
  46. return [[self viewList] makeObjectsPerform:aMessage];
  47. }
  48.  
  49. If you wish to set up something that uses parameter passing. then you 
  50. could try this.
  51.  
  52. - makeSquaresPerform:(SEL) aMessage with: anObject {
  53. return [[self viewList] makeObjectsPerform:aMessage with: anObject];
  54. }
  55.  
  56. Basically its makes use of behaviour already in List. 
  57.  
  58. replace [self viewList] with your list's reference or method
  59. to retrieve its reference.
  60.  
  61. Hope this helps.
  62.  
  63. This code assumes that all your objects will perform "aMessage" perhaps
  64. it might be worthwhile to check using Object's respondsTo: first.
  65.