Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!samsung!rex!rouge!gator.cacs.usl.edu From: pcb@gator.cacs.usl.edu (Peter C. Bahrs) Newsgroups: comp.object Subject: RE: Should objects draw themselves? Message-ID: <12873@rouge.usl.edu> Date: 8 Aug 90 18:21:04 GMT Sender: anon@rouge.usl.edu Organization: The Center for Advanced Computer Studies, USL Lines: 58 >Article 1064 of comp.object: >... >QUESTION: Should a `Shape' be able to `draw' itself? > >The usual answer is ABSOLUTELY. I have to totally agree, since adding a >new Shape (Hexagon, for example) only requires adding code rather than >changing existing code (as would be required if there were a global `draw' >function). This is the usual ``don't operate on objects; instead enable >the object to provide services for you''. > >However: what if I add a new terminal type? Or what if I want a textual >... >The best I've come up with is this: > > GraphicalShape TextualShape <-- One per `view' > \ / > \ / > Shape > / | \ > / | \ > / | \ > Square Circle Hexagon <-- One per concrete Shape > > class GraphicalShape { public: void graphical_draw() = 0; }; > class TextualShape { public: void textual_draw() = 0; }; > class Shape : public GraphicalShape, public TextualShape { }; > I agree somewhat, but consider the following. What happens when these objects have to draw themselves in relation to other objects, i.e. if objects have priorities (such as in a graphics system where farther objects are drawn first 'painters algorithm')? This is compicated when user defined objects contain the drawable primitives. Suppose object A has a list of squares and circles and only N of the should be drawn in state S. Now there are multiple objects like A and all of them need theirselves represented in some relation R to each other. I guess some procedure sifts through all objects to be drawn, queries each object by sending them some kind of 'where are you so I can compare you to others and determine if you should really draw yourself now' message. The other technique is is to pass the drawing area to each object and since each object must be made of primitive(s) that can draw themselves, then this object can draw itself. What about 3D drawables...3d- to 2d conversion, perspective transformation? /*----------- Thanks in advance... --------------------------------------+ | Peter C. Bahrs | | The USL-NASA Project | | Center For Advanced Computer Studies INET: pcb@gator.cacs.usl.edu | | 2 Rex Street | | University of Southwestern Louisiana ...!uunet!dalsqnt!gator!pcb | | Lafayette, LA 70504 | +-----------------------------------------------------------------------*/