What Does It Mean to Program to an Interface

Simple: “Coding to interfaces, not implementation.” Coding to interfaces is a technique to write classes based on an interface; interface that defines what the behavior of the object should be. It involves creating an interface first, defining its methods and then creating the actual class with the implementation.

What is programming to an interface?

Simple: “Coding to interfaces, not implementation.” Coding to interfaces is a technique to write classes based on an interface; interface that defines what the behavior of the object should be. It involves creating an interface first, defining its methods and then creating the actual class with the implementation.

Should you always program to an interface?

Sylvia wrote a great summary why you should use it: Interfaces make your code less brittle. If implementations change, your code will still work—as long as the interface doesn’t change. However, there is an urging question, when programming against an interface pattern should be used.

Maya Lin-Takahashi

Maya Lin-Takahashi

Consumer Tech & Gadget Reviewer

Maya is a hardware enthusiast who tests and reviews smart home devices, smartphones, wearables, and audio gear. She focuses on practical consumer value and build quality.

Share this article
Twitter Facebook Pinterest