Re: interfaces




"Barfy the Wonder Camel" <googroup@xxxxxxxx> wrote in message
news:1181317642.217515.198600@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
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

An abstract class allows this as well.

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.

Again, an abstract class works the same, except that abstract classes are
far more powerful. However, .NET limits base classes to single inheritance,
but allows multiple interfaces in the base list.


.



Relevant Pages

  • Re: [PHP] What is the practical use of "abstract" and "interface"?
    ... If your code doesn't have an API and clear separation of parts, then neither abstract classes nor interfaces are useful to you. ... If you're not writing OOP code, then neither is of any use to you as both are OOP concepts. ... All component A needs to know about component B is that it implements interface Foo, meaning that you know, absolutely, that you can call $b->fooand get back a string and $b->barand get back a database connection, because the interface says so. ...
    (php.general)
  • Re: PHP5 Bug?? extended abstract type enforcement
    ... >> Abstract classes can never be instantiated, only implementations can. ... >> wrong interface, ... from which lists are derived. ...
    (comp.lang.php)
  • Re: Adding member property to abstract class
    ... I just had the wrong syntax when I added the field (I must have been ... error, and because I'm new to abstract classes, I /assumed/ that they ... >> actually implementing the method in the interface. ... its methods act as defaults that handle the requirements of the ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Ensuring a method exists
    ... Pascal Costanza ha escrito: ... When different classes offer similar functionality and you want ... Interface types are more flexible than class types because the former ... which is an especification of abstract classes in C++. ...
    (comp.lang.lisp)
  • Re: Ensuring a method exists
    ... Pascal Costanza ha escrito: ... When different classes offer similar functionality and you want ... Interface types are more flexible than class types because the former ... which is an especification of abstract classes in C++. ...
    (comp.lang.lisp)