Geeks With Blogs
Random Musing Putting it together one piece at a time...

Interface can be quite confusing for some people, especially if they have not been exposed to applications that requires its implementation. Microsoft's definition of an Interface is

Now if you take out all the technical jargons and got asked to explain the concept of an Interface to your boss, who has absolutely no technical background, you probably will say that an Interface can basically be explained as a contract.

Imagine company A engaging a solution provider, company B for example, for a solution. Company B prepared a contract and get A to buy B's services. After signing the contract and buying the services, B will have to carry out whatever requirements that is stated in the contract. How does this map to the concept of an Interface? Imagine that an Interface as an contract (as provided by company B to company A), and the class that implements that contract as company A.

Basically an Interface will define all the methods, delegates, events and properties that is to be commonly used, and it'll require a class to inherit and then implement it in order for it to work.

Example:

//interface
interface ICompanyBContract
{
      void YourRequirements()
}

//class that consume and implements the interface, everything within the interface must be implemented
public class CustomerA : ICompanyBContract
{
      public CustomerA()

      public void YourRequirements()
      {
            //code to solve your requirements
      }
}


The difference between a class and an interface is that a while a class has direct implementations of its properties, delegates and such, Interfaces does not have a direct implementation. This is very useful when your application allows an architecture which requires your definition of all your properties, delegates, methods and events, and have them inherited and implemented and interchanged with different classes and components.

Interfaces, like classes, can inherit other Interfaces. Likewise, if a class consume an Interface that has previously inherited another Interface, all its members will have to be implemented by that class.

Posted on Thursday, February 1, 2007 2:24 PM | Back to top


Comments on this post: Interface made simple

No comments posted yet.
Your comment:
 (will show your gravatar)


Copyright © Nestor | Powered by: GeeksWithBlogs.net