Understanding: Interfaces

When creating applications, there sometimes comes the need to use interfaces. An ‘interface’ is one of the types available in the VB .Net language (and for that matter almost all other OO languages). Interfaces are perhaps one of the most difficult types to explain. Most writeups or articles explain it as a contract; a contract that binds two classes together.

I, on the other hand, prefer to say: Interfaces can be best explained as a ‘language'; like English or Arabic. Sometimes classes need to communicate between each other, if written by the same person, that would not be much of a problem. But sometimes these classes are written by a number of different people, probably people from another firm, country and/or continent.

In order to communicate with each other, like us humans (at least those of us who call themselves that :-)) classes need a common language they all speak. This language must be understood by all and follow the same rules and regulations everywhere.

In programming this is called an interface. It is a way of ensuring all related classes speak the same language. For example, if class A wants class B to do a certain task, the only way for class A to insure that class B can do the task, is by checking if class B implements the ICanDoTask (for example) interface.

Unlike inheritance, a class can implement an unlimited number of interfaces.

Perhaps you can understand more if you read this: http://www.vbip.com/books/1861004915/chapter_4915_10.asp.

Enjoy!

Leave a Reply

Your email address will not be published. Required fields are marked *


*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>