On May 19, 2008, at 10:48 AM, Greg Titus wrote:

You've translated the Objective-C syntax into C# syntax, but the point of the question is to think about what prepareWithInvocationTarget() does. How would you write that method in C#?

Well, it was a poorly stated question then. His primary presentation asked how I'd write the code he posted, not the supporting implementation details.

In Objective-C, after you call -prepareWithInvocationTarget: on an NSUndoManager, it then accepts _any_ message call of any kind. It is completely and totally dynamic. It accepts messages from your application which weren't defined and didn't exist when the NSUndoManager class was compiled. The undo manager accepts the message, saves the target and method invocation with an arbitrary number of arguments and is able to re-invoke it later on the original target when the user asks you to Undo.

Thanks. That certainly makes the example more clear, and make more sense.

That said, because of the existence of reflection in C# and Java, similar functionality isn't really that difficult in those languages. It's trivial to take any arbitrary class or instance of a class and invoke any arbitrary named method with an arbitrary number of arguments, immediately or later as necessary.

I would agree that in the light you've offered, the NSUndoManager offers a somewhat more compelling use case than previous examples. But it's not true that the C# or Java version would be significantly different. They would be only slightly more verbose (though yes, I admit...they would be more verbose, albeit slightly).

Pete
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to