Re: interface question

Tech-Archive recommends: Fix windows errors by optimizing your registry

From: Christopher Kimbell (a_at_b.c)
Date: 05/08/04


Date: Sat, 8 May 2004 22:49:56 +0200

Interfaces provide another level of abstraction, you can have two objects
that implement the same interface, but are implemented completely different.
The System.Data namespace contains a number of interfaces like IDataReader
and IDataAdapter. If your code uses the interfaces instead of the actual
class, it would be easier to swap between Sql and Oracle data providers.

Interfaces can also reduce the number of assemblies that has to be rebuild
when something changes. If you change an assembly that has a strong name,
any assembly that uses the changed assembly has to be rebuilt. You can get
around this with some configuration, but it's not very nice. If you seperate
the interfaces into an assembly, the users will reference this assembly, not
the implementing one. If the interface hasn't changed, you only have to
rebuild the implementing assembly. This is very useful in large complex
systems.

Interfaces are very usefull when you want to build extensible software, like
providing a plugin.

I hope this shows you the value of interfaces.

Chris

"John Underwood" <johnwadeunderwood@yahoo.com> wrote in message
news:f004e9c2.0405081144.6fd27f6@posting.google.com...
> Hi.. I was looking at interface, and I have a example in the docs i'll
> paste below.. I'm not grasping what you would gain by using a
> interface, does any one have a brief description of their benefit?
>
>
> Thanks,
>
> John Underwood
>
>
> Visual Studio .Net example below:
> Example
> The following example demonstrates interface implementation. In this
> example, the interface IPoint contains the property declaration, which
> is responsible for setting and getting the values of the fields. The
> class MyPoint contains the property implementation.
>
> // keyword_interface.cs
> // Interface implementation
> using System;
> interface IPoint
> {
> // Property signatures:
> int x
> {
> get;
> set;
> }
>
> int y
> {
> get;
> set;
> }
> }
>
> class MyPoint : IPoint
> {
> // Fields:
> private int myX;
> private int myY;
>
> // Constructor:
> public MyPoint(int x, int y)
> {
> myX = x;
> myY = y;
> }
>
> // Property implementation:
> public int x
> {
> get
> {
> return myX;
> }
>
> set
> {
> myX = value;
> }
> }
>
> public int y
> {
> get
> {
> return myY;
> }
> set
> {
> myY = value;
> }
> }
> }
>
> class MainClass
> {
> private static void PrintPoint(IPoint p)
> {
> Console.WriteLine("x={0}, y={1}", p.x, p.y);
> }
>
> public static void Main()
> {
> MyPoint p = new MyPoint(2,3);
> Console.Write("My Point: ");
> PrintPoint(p);
> }
> }
> Output
> My Point: x=2, y=3



Relevant Pages

  • Re: MprAdminInterfaceEnum
    ... > Trying to enumerate interfaces on RRAS. ... the enumeration cannot be continued. ... > public static extern int MprAdminInterfaceEnum( ...
    (microsoft.public.dotnet.framework.interop)
  • Giant packets on a 10Gig interface
    ... switchport trunk encapsulation dot1q ... The 10Gb interfaces on each end of this link are reporting a large number of giants when I do a show int. ... input packets with dribble condition detected ...
    (comp.dcom.sys.cisco)
  • Re: ssize_t and size_t
    ... Nate Eldredge wrote: ... I was thinking about interfaces like this one for Unix read ... The "count" parameter was originally an int, therefore it was not possible to pass a count larger than INT_MAX, and therefore a negative return value unquestionably meant an error. ... The result is what Nate explains: you can't meaningfully pass a value larger than SIZE_MAX/2 to read, even though the parameter has type size_t -- and most implementations will check for that case and immediately return an error if you try it. ...
    (comp.lang.c)
  • Re: Object orientation.....
    ... void *draw(unsigned char *rgb, int width, int height, int x, int y); ... Thus you build your object from interfaces. ...
    (comp.lang.c)
  • How to get all IP Addresses on AIX using C++
    ... I have been trying to get all ip addresses from all interfaces, ... int main ... printf("There is trouble of sock!! ... int rval = ioctl(sock, SIOCGIFADDR, ifr); ...
    (comp.unix.programmer)