Thread View: comp.sys.next.programmer
1 messages
1 total messages
Started by Paul Burchard
Tue, 21 Jul 1992 23:16
implementing "tools"---performv:: selector switcharoo?
Author: 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...''
--------------------------------------------------------------------
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads