Interface

Why Trust Techopedia

What Does Interface Mean?

An interface specifies a group and/or a set of methods, which have not been implemented. When a class implements an interface, the class provides an implementation to all defined interface methods. A single class may implement any number of interfaces. Sometimes, constant declarations are included in an interface, along with method definitions.

Advertisements

Disadvantages for the interface is that all interface methods must be public and only abstract methods may be used in an interface. However, because these methods are implicit, they are not declared.

Techopedia Explains Interface

An interface is best explained with an example. The most common example is the connections among a television, a remote control, and a user. A user turns on the TV by using the remote control and may not necessarily know anything about the TV’s wiring. Thus, the remote control is an interface between the user and the television set.

Similarly, when a class implements an interface, the method functionalities are implemented without knowledge of the method's inner workings.

The following are examples of when to use an interface:

  • When two or more unrelated classes implement a set of methods, which may be defined in an interface and then implemented by the classes.
  • When an interface is a good alternative to multiple class inheritance.
  • When an object’s functionality is revealed without described implementation.
Advertisements

Related Terms

Margaret Rouse
Editor

Margaret jest nagradzaną technical writerką, nauczycielką i wykładowczynią. Jest znana z tego, że potrafi w prostych słowach pzybliżyć złożone pojęcia techniczne słuchaczom ze świata biznesu. Od dwudziestu lat jej definicje pojęć z dziedziny IT są publikowane przez Que w encyklopedii terminów technologicznych, a także cytowane w artykułach ukazujących się w New York Times, w magazynie Time, USA Today, ZDNet, a także w magazynach PC i Discovery. Margaret dołączyła do zespołu Techopedii w roku 2011. Margaret lubi pomagać znaleźć wspólny język specjalistom ze świata biznesu i IT. W swojej pracy, jak sama mówi, buduje mosty między tymi dwiema domenami, w ten…