Interface tutorial....

vis781

Well-known member
Joined
Aug 30, 2005
Messages
2,016
Location
Cambridge, UK
Programming Experience
5-10
After reading a post or two on this forum, and struggling with the concept myself. I was wondering if anyone would take on the task of trying to write a good interface tutorial and an example of how they can be used. I think that there is much confusion where this part of Vb.net is concerned, as much from me as anyone. In a post yesterday someone had posted a link to an example of using an interface, and it was called a bad example. So does anyone think they could explain it for all to see and read? (i'd have a go, but i don't think that i use them to their full potential)
 
Here's a simple real world example: Transport. You might have a car, bus, plane, horse, bicycle or whatever but they are all modes of transport so if you need a way to get from A to B you can use any one of those objects because all modes of transport are capable of going from A to B, even though the actual objects may be completely different.

To transfer that to programming, if you need a way to be able to treat a number of possibly very different types in the same way then you define an interface that describes the commonality and then have every type implement that interface. A good example is IList. Any type that implements IList can be bound to a DataGrid. Nothing else about the type matters.
 
Back
Top