home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / sys / next / programm / 5157 < prev    next >
Encoding:
Text File  |  1992-07-21  |  2.1 KB  |  47 lines

  1. Newsgroups: comp.sys.next.programmer
  2. Path: sparky!uunet!gatech!news.byu.edu!ux1!fcom.cc.utah.edu!news
  3. From: burchard@horizon.math.utah.edu (Paul Burchard)
  4. Subject: implementing "tools"---performv:: selector switcharoo?
  5. Message-ID: <1992Jul21.231630.25221@fcom.cc.utah.edu>
  6. Sender: news@fcom.cc.utah.edu
  7. Organization: University of Utah Computer Center
  8. Date: Tue, 21 Jul 92 23:16:30 GMT
  9. Lines: 36
  10.  
  11. I'm making an abstract superclass whose subclasses will want to define a  
  12. variety of processing "tools".  Each of the tools is a method; the methods have  
  13. different names but identical declarations in terms of arg and return types.   
  14. The superclass will ask the subclass what tool to use when, and then apply that  
  15. tool in its operations.  If all the args were id's this would be trivial to  
  16. implement, using Object's "perform" methods, but that's not possible in my  
  17. situation.
  18.  
  19. It looks like the way to do it is to forward:: an unimplemented generic tool  
  20. message from the object to itself, BUT to slip in the correct specific selector  
  21. like this:
  22.  
  23.     - forward:(SEL)aSelector :(marg_list)argFrame
  24.     {
  25.         SEL tool = [self toolForMode:mode]; // subclass method
  26.         if(aSelector == @selector(genericTool:::)) // unimplemented
  27.         return [self performv:tool :argFrame];
  28.         return [self doesNotRecognize:aSelector];
  29.     }
  30.  
  31. Now it is completely clear from the docs that you can performv:: the exact  
  32. selector and arg frame passed to forward::, but it is not clear whether it is  
  33. kosher to substitute selectors.  The forward:: docs offer the following vague  
  34. encouragement:
  35.     An implementation of the forward:: method can do more than just forward 
  36.     messages.  It can, for example, locate code that responds to a variety 
  37.     of different messages, thus avoiding the necessity of having to write a 
  38.     separate method for each selector.
  39.  
  40. So am I asking for trouble?  This will probably work for now, but is it  
  41. "cheating"?
  42. --
  43. --------------------------------------------------------------------
  44. Paul Burchard    <burchard@math.utah.edu>
  45. ``I'm still learning how to count backwards from infinity...''
  46. --------------------------------------------------------------------
  47.