What is an Interface in programming?

AXE I/O, AXE I/O Solo, iRig Stomp I/O, Guitar and Bass Audio Interfaces/Controllers, iRig Keys I/O and the iRig Keys family of MIDI controllers

What is an Interface in programming?

Postby stim54 » Sat Aug 17, 2019 11:06 am

An interface is basically a class with no implementation that is intended to be subclassed so that a related set of classes all share a common set of methods. This lets you program parts of your code in a way where you don't have to worry about which of the subclasses you're working with, and anyone else using your code can implement their own subclass from that Interface that should work.

Using the common programming textbook example of classes representing different kinds of vehicles, we could imagine that we're creating a video game where you have different kinds of vehicles you can drive and pressing a button causes the vehicle to accelerate. So we want to make a Vehicle interface that defines an accelerate method, but there's no generic implementation for accelerate, since each vehicle accelerates differently. So then we'd subclass the Vehicle interface in a Car class, a Train class, an Airplane class, etc., and each would implement the accelerate function in the way that specific vehicle should accelerate.

Edit: In Java there's a specific keyword for defining an Interface, but any object-oriented language should support this type of design. Your interface would just be another Class that either doesn't implement the functions defined, if the language allows that, or implements dummy or placeholder functions that would be replaced by a subclass.
stim54
 
Posts: 1
Joined: Sat Aug 17, 2019 11:05 am

Re: What is an Interface in programming?

Postby dlgebert » Mon Aug 19, 2019 4:44 am

This post has been deliberately deleted. At the time I didn't realize this was robotic spam.

Dave
User avatar
dlgebert
 
Posts: 371
Joined: Sun Dec 01, 2013 11:51 pm


Return to Interfaces & Controllers