Difference between Objective-C delegates and C# delegates.

I currently update my knowledge on C# since the early days of C# .NET.
Although many things similar to Objective-C/Cocoa are added to C# .NET, some are somehow different. For example delegate is one of them.

In Objective-C, delegate is a delegate object which do something for other objects.
So, if the “other” object set the delegate object as a delegator, the delegator object handles messages to the “other” object for the “other” object.

However, in C#, it is more like function pointer.
Well, function pointer can be used in “delegate” pattern.
However, in .NET framework, delegates look to be used more as a way to register “callback” functions. So, rather than “delegate” itself, it is a building block for “delegate” pattern.

Just like C++, people can make their own delegate pattern by message forwarding ( in Obj-C term) or by defining methods in a “representative” object, setting that object as a delegate and calling those methods. This means that without using C#’s delegate type you can make delegate pattern.

So, I don’t think using the term “delegate” in C# for its “delegates” type sounds like misnomer. ( again, because it resembles more like function pointer rather than delegator object. )

I have used Win32, MFC since 1990. The consistent naming of classes, functions and methods in MS API & frameworks is that their names sometimes don’t match what they are for and what they do.
Collapse this post

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: