Article View: comp.sys.next.programmer
Article #162implementing "tools"---performv:: selector switcharoo?
From: Paul Burchard
Date: Tue, 21 Jul 1992 23:16
Date: Tue, 21 Jul 1992 23:16
36 lines
2208 bytes
2208 bytes
I'm making an abstract superclass whose subclasses will want to define a
variety of processing "tools". Each of the tools is a method; the methods have
different names but identical declarations in terms of arg and return types.
The superclass will ask the subclass what tool to use when, and then apply that
tool in its operations. If all the args were id's this would be trivial to
implement, using Object's "perform" methods, but that's not possible in my
situation.
It looks like the way to do it is to forward:: an unimplemented generic tool
message from the object to itself, BUT to slip in the correct specific selector
like this:
- forward:(SEL)aSelector :(marg_list)argFrame
{
SEL tool = [self toolForMode:mode]; // subclass method
if(aSelector == @selector(genericTool:::)) // unimplemented
return [self performv:tool :argFrame];
return [self doesNotRecognize:aSelector];
}
Now it is completely clear from the docs that you can performv:: the exact
selector and arg frame passed to forward::, but it is not clear whether it is
kosher to substitute selectors. The forward:: docs offer the following vague
encouragement:
An implementation of the forward:: method can do more than just forward
messages. It can, for example, locate code that responds to a variety
of different messages, thus avoiding the necessity of having to write a
separate method for each selector.
So am I asking for trouble? This will probably work for now, but is it
"cheating"?
--
--------------------------------------------------------------------
Paul Burchard <burchard@math.utah.edu>
``I'm still learning how to count backwards from infinity...''
--------------------------------------------------------------------
Technical Details
Message-ID:
<1992Jul21.231630.25221@fcom.cc.utah.edu>Path:
arc1-ca.pugleaf.net!sparky!uunet!gatech!news.byu.edu!ux1!fcom.cc.utah.edu!newsShow Full Headers
Complete Article Headers
Newsgroups: comp.sys.next.programmer Path: arc1-ca.pugleaf.net!sparky!uunet!gatech!news.byu.edu!ux1!fcom.cc.utah.edu!news From: burchard@horizon.math.utah.edu (Paul Burchard) Subject: implementing "tools"---performv:: selector switcharoo? Message-ID: <1992Jul21.231630.25221@fcom.cc.utah.edu> Sender: news@fcom.cc.utah.edu Organization: University of Utah Computer Center Date: Tue, 21 Jul 92 23:16:30 GMT Lines: 36