Ted Leung on the air
Ted Leung on the air: Open Source, Java, Python, and ...
Ted Leung on the air: Open Source, Java, Python, and ...
Tue, 30 Sep 2003
CLR multimethod dispatch
Some friends and I have been running a study group here on the Island, and we've been looking at the GoF Design Patterns book. Last week we covered the Visitor pattern, and I pointed out that the pattern largely goes away in languages with multimethod dispatch. So I read Surana's post about C# MultiMethods with great interest. His post explains how multimethods work, but not how you would implement them with Type.InvokeMember. I looked at the MSDN pages for InvokeMember, and saw a hairily complex method. Googling didn't turn up anything obvious either. So if there's anyone out there that's used InvokeMember to do multimethod dispatch, and is willing to show their code, I'd be interested in seeing such a thing.
[12:33] |
[computers/programming] |
# |
TB |
F |
G |
3 Comments |
On the topic of Design Patterns "going away," Peter Norvig's Design Patterns Dynamic Programming states that "...in Dylan or Lisp 16 of 23 patterns are either invisible or simpler."
Posted by Robert Sayre at Tue Sep 30 15:18:53 2003
Posted by Robert Sayre at Tue Sep 30 15:18:53 2003
Robert,
Yes, I'm aware of the paper. See
http://www.sauria.com/blog/2003/02/11#40
Posted by Ted Leung at Tue Sep 30 18:16:44 2003
Yes, I'm aware of the paper. See
http://www.sauria.com/blog/2003/02/11#40
Posted by Ted Leung at Tue Sep 30 18:16:44 2003
Since the .NET weenies made Delegate a special runtime type, you can't make this a subclass of Delegate the way it ought to be.
class MultiMethod {
object target ;
string methodName ;
public MultiMethod (object t, string m) {
target = t ; methodName = m ;
}
public object Invoke (params object[] args) {
return Type.InvokeMember (methodName, BindingFlags.Public | BindngFlags.InvokeMethod, null, target, args) ;
}
}
Posted by surana at Tue Oct 21 15:14:23 2003
class MultiMethod {
object target ;
string methodName ;
public MultiMethod (object t, string m) {
target = t ; methodName = m ;
}
public object Invoke (params object[] args) {
return Type.InvokeMember (methodName, BindingFlags.Public | BindngFlags.InvokeMethod, null, target, args) ;
}
}
Posted by surana at Tue Oct 21 15:14:23 2003
You can subscribe to an RSS feed of the comments for this blog:
Add a comment here:
You can use some HTML tags in the comment text:
To insert a URI, just type it -- no need to write an anchor tag.
Allowable html tags are:
You can also use some Wiki style:
URI => [uri title]
<em> => _emphasized text_
<b> => *bold text*
Ordered list => consecutive lines starting spaces and an asterisk
To insert a URI, just type it -- no need to write an anchor tag.
Allowable html tags are:
<a href>
, <em>
, <i>
, <b>
, <blockquote>
, <br/>
, <p>
, <code>
, <pre>
, <cite>
, <sub>
and <sup>
.You can also use some Wiki style:
URI => [uri title]
<em> => _emphasized text_
<b> => *bold text*
Ordered list => consecutive lines starting spaces and an asterisk