Alex Rivera | Logout

What is the definition of "interface" in object oriented programming

Asked 2010-05-19T15:34:18.263
162

A friend of mine goes back and forth on what "interface" means in programming.

What is the best description of an "interface"?

To me, an interface is a blueprint of a class. Is this the best definition?

Edit
Report

2 Answers

25

I don't think "blueprint" is a good word to use. A blueprint tells you how to build something. An interface specifically avoids telling you how to build something.

An interface defines how you can interact with a class, i.e. what methods it supports.

answered 2010-05-19T15:38:09.437
1

An interface defines what a class that inherits from it must implement. In this way, multiple classes can inherit from an interface, and because of that inherticance, you can

  • be sure that all members of the interface are implemented in the derived class (even if its just to throw an exception)
  • Abstract away the class itself from the caller (cast an instance of a class to the interface, and interact with it without needing to know what the actual derived class IS)

for more info, see this http://msdn.microsoft.com/en-us/library/ms173156.aspx

answered 2010-05-19T15:48:28.663

Your Answer