Re: Interface VS Delegate

From: Angel J. Hernández (angeljesus14_at_hotmail.com)
Date: 08/25/04


Date: Tue, 24 Aug 2004 21:55:34 -0400

Hi there... uhm... there are a couple of things you should be aware of...

Interfaces allow us to extend some object's functionality, it's a contract
between the interface and the object that implements it. It is used to
simulate multiple inheritance in C#. In the other hand, we have delegates...
They're just safe callbacks or function pointers. They allow us to notify
that something has happened (Events). As you can see they're different as
well as their use. In your case I'd recommend you to implement an interface
to the objects you want to sort unless... you want to implement some sort of
quicksort algorithm that has a callback (delegate in .NET) as a parameter.

Regards,

-- 
Angel J. Hernández M.
MCSD
"Phill" <wackyphill@yahoo.com> escribió en el mensaje
news:ac94631d.0408241611.553b6c89@posting.google.com...
> When should you use an interface over a delegate?
>
> Like if you have a class that needs to sort various types of objects.
> Should it use a delegate to do the sorting or require that the objects
> implement a sorting interface?
>
> I read that delegates are smaller and of finer granularity than
> interfaces. What does that mean exactly? Does it mean they are more
> efficient?
>
> Thanks.


Relevant Pages

  • Re: Delegates VS interfaces - some confusion
    ... Because when implementing an interface, only one method can implement one member of the interface, whereas with a delegate you can specify the   ... There's a single identifier to refer to in order to get and execute the method, but the actual method that is executed depends on some run-time logic: ... That is, the polymorphism implemented using an interface is determined for a given type at compile time, whereas the polymorphism implemented using a delegate can vary in behavior at run time according to any arbitrary logic the class providing the delegate wants to implement. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Delegates VS interfaces - some confusion
    ... the delegate is pubilc, it's already accessible anyway. ... situation and so the example with a three-method interface doesn't really ... member level polymorphism, ... single-method interface in that much more concise way. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Delegates VS interfaces - some confusion
    ... one member of the interface, whereas with a delegate you can specify ... delegate void Func; ... algorithm not changing at run time and how that makes it intrinsic to ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Multi-threading article finally "finished" - reviewers welcome
    ... >> I think you could do all of that without deriving from the base class ... you can do that with a delegate. ... >> languages provide facilities which make a design cleaner, ... you said the interface remains the same. ...
    (microsoft.public.dotnet.general)
  • Re: Nemethis Tablelist widget vs. Hobbs Tktable widget
    ... > An Cobol man would say - if I must be quickly I sort using ... >> Csaba's Tablelist widget, and I'm looking for some feedback from ... concentrate more on interface specification then interface users can ... encapsulates a certain functionality. ...
    (comp.lang.tcl)