Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Syntax question on interfaces
Message
De
19/01/2004 15:48:19
 
 
À
19/01/2004 12:26:10
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Divers
Thread ID:
00868001
Message ID:
00868296
Vues:
16
This message has been marked as the solution to the initial question of the thread.
Kevin,

That was exactly my first thought about Interfaces ... what good are they? But then I learned ... the main benefits of defining Interfaces is that if a lot of objects implement the same Interface, you can reference properties or methods on the Interface and not have to know exactly which class is being used.

For example, say I have two kinds of TextBoxes ... MyTextBox, MySpecialTextBox. They both implement an Interface, say IBindThis, which has a method called MyBinding(). So, when you're doing some binding on your form, you can check whether the object (the TextBox) implements the Interface and work from there. Something like this:
// Assume you are passing an unknown type of object to this
if (oControl is IBindThis)
   ((IBindThis)oControl).MyBinding();
As you can see, you can call the MyBinding() method because you know that this particular object will have that method defined. Furthermore, you can cast the object to the Inteface in order to be able to call it's method.

Hope that clears things up a bit.

~~Bonnie


>well, yes and no ;)
>
>I went back and read the two pieces of documentation that I have on them. What I'm a bit hazy on is the benefit that custom interfaces provide. I'm sure they do, but I'm just not quite 'getting it'. After a year and a half, I still find myself in 'learning mode' with .NET!
>
>Thanks,
>Kevin
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform