Re: interfaces

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



On Jun 7, 4:12 pm, "abcd" <a...@xxxxxxxx> wrote:
Can someone tell me whats the exact advantage of Interfaces in C#. To me
abstract classes serves the purpose and have all good things then what is
special about interfaces...can someone tell me some real example from
system, user, developer point of view....

An interface will allow you to publish a standard, um, interface, for
making use of a functionality. For instance, you may write a sorting
library, and you want it to be generally available to other classes.
You publish an interface, consisting of a set of functions, that
classes have to implement in order to be able to use your library. Or
if you want your class to be able to implement BeginInvoke and
EndInvoke, you have to implement the ISynchronizeInvoke interface.
Implementing just means you have to supply a version of the functions
defined by the interface within your class.

..NET implements a number of interfaces, all of which start with "I",
as in IComparable, ICollection, etc. Classes that implement the
interface can use the functionality.

So if you are writing a class "smee" that you want to be able to sort,
use asynchronous communications, and serialize to a file (or
something), you'd define it as

class smee : IComparable, ISynchronizeInvoke, ISerializable {}

and implement all the required methods for those interfaces, then you
can hand a smee to any method that requires one of those interfaces.


.



Relevant Pages

  • Re: multiple inheritance
    ... slice" of functionality, and use MI to get at it from a class that has this ... to think much more about the design at this level than any most programmers ... I'm a MI AND Interface fan. ... Point 1: Aggregation ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: setting local variables in a binding
    ... need to do to try to keep things from breaking since Ruby is dynamic. ... functionality into the classes your design is a tad less modular. ... not have to interface to other code to perform a broader function. ...
    (comp.lang.ruby)
  • Re: Great SWT Program
    ... orthogonal to whether or not a program has a decent user interface. ... A few also knew the arrow keys existed. ... "useful functionality required to qualify the application as an IDE". ... Or maybe you simply use "real text editor" as a synonym for IDE; ...
    (comp.lang.java.programmer)
  • Re: When would you use an abstract class and when an interface?
    ... An abstract class is useful when you need a substantial amount of ... An example of where an interface is useful is where you have unrelated ... items that need to provide some similar functionality in a uniform ... but where the system caches them to disc as well as HTML ...
    (comp.lang.php)
  • Re: Ensuring a method exists
    ... When different classes offer similar functionality and you want ... Interface types are more flexible than class types because the former ... (defgeneric rem (collection object)) ... It's left up to the responsibility of the programmer to define the right methods, or to leave them out when they are actually not necessary. ...
    (comp.lang.lisp)