Link to home
Start Free TrialLog in
Avatar of CubeRoot
CubeRootFlag for United States of America

asked on

In simpliest terms: Interface

I've been programming for years in vb.net and someone never had to bother with creating an Interface. Could someone explain why I need it, what it does for me? I know this seems to basic but someone it's slipped through the cracks on me.
ASKER CERTIFIED SOLUTION
Avatar of kaufmed
kaufmed
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
P.S.

I wrote the examples in C# because you had the question tagged as C#. If you need them in VB I can translate them for you  = )
Avatar of CubeRoot

ASKER

C# is perfect. I'll read over this a few times tomorrow morning. Thank you very much.
So Interface is just contract and we are implementing it. Suppose my mother given me list of items to purchase it from shopping mall. So this list acts as interface. In fact I am implementing this list in shopping mall by purchase the items.......
I'm starting to get the picture. This is very helpful. If I declare a class and assign it an interface it takes on the attributes of the interface. Is IEnumerable and interface or is it different? I ask but it has the I preface but it's definitely handled differently.
Yes, IEnumerable is an interface. The convention in .NET is to prefix any interface definitions with an "I" for clarity. (This of course is not imply that anything which starts with an "I" is an interface, but typically if you see "ISomeOtherWord", then it is probably an interface. "Iremainderofword" would most likely not be an interface.) You can always consult the documentation or the Object Browser (or Intellisense) in Visual Studio to determine whether or not a type is an interface definition.

What do you mean by, "...it's definitely handled differently?"
Sorry for taking a few days to reply. Work is keeping me busy and by the time I get home..it's eat supper, read up on whatever I'm having issues with at work and get to bed. I said it's definitely handled differently because IEnumberable seems to be used to convert a datatype so it can be used for a foreach function where I usually see Interfaces used to extend a classes to take on additional properties.
Yes, in that sense IEnumerable is unique.
Avatar of sbornstein2
sbornstein2

Just wanted to say this answer to explaining an interface is what I have been looking for a long time now to explain it in the most simplest clearest form.   Thanks for posting this response.