Program to an Interface

phrase

say it: “PROH-gram too an IN-ter-fays” /ˈproʊɡræm tu æn ˈɪntərˌfeɪs/

Writing code that asks for a promise, such as "something that can take a payment", instead of naming one specific class.

What does it mean to program to an interface?

To program to an interface is to write code that asks for what it needs, a promise such as "something that can take a payment", instead of naming one specific class, such as a card reader. Any class that keeps the promise can then be handed in: a gift card next month works without the checkout code changing. The 1994 book that named the classic design patterns put it as "program to an interface, not an implementation".

In a sentence

  • “Because we program to an interface, the gift card worked at checkout the day it was written.”

Level: Apprentice · More OOP terms at this level

Updated