This is a design principle in object-oriented programming:

Program to an interface, not an implementation.

At last now I know for sure what the principle means (thanks to @DanBron in the comments) but as a non-native speaker I fail to understand what the phrase "program to" means in that sentence.

It has been suggested that it means "write to" or "program against" but I still can't risk an interpretation: which example usage of "write to" would be similar? Is "program against" a phrasal verb? What does "against" mean in that case?


1 Answer 1


Programming is an activity that involves writing a program. However, when you are doing that, you write your program in such a way that it will interact with other systems. This is commonly expressed as programming against X:

I program in C# against an Oracle database.

Programming can be seen as a way to communicate with a computer system. You are telling it what it should do, and you are "talking" to surrounding system parts or comonents.

In that light, one could be said to be programming to a database, a webservice, an external component, a class.

Indeed the advice to prgram to an interface, rather than an implementation, means you should address the exposed interface, or contract, rather than the implementation of that interface or contract.
It also means that you should make that possible for other programmers, by ensuring you provide such an interface or contract!

  • It's a similar usage to the phrase "to adhere to a set of guidelines". ie, the guidelines will inform us what we need to do, and we follow them. Aug 5, 2016 at 14:23
  • There is some semantic gap preventing me from understanding what "to" translates to in "adhere to" or "program to", but I was able to understand this answer clearly. Based on it I'd word the principle as "program addressing interfaces, not implementations" or "write code which calls only interfaces". Is this a reasonable interpretation?
    – Piovezan
    Aug 5, 2016 at 17:42
  • @oerkelens Have I missed anything in my interpretation (besides your last paragraph)? In it I mean interfaces as contracts or "the sanctioned parts".
    – Piovezan
    Aug 9, 2016 at 14:40
  • @Piovezan I think your interpretation is reasonable and valid :)
    – oerkelens
    Aug 10, 2016 at 10:37
  • @oerkelens Thank you! And thanks again for the clear explanation :)
    – Piovezan
    Aug 10, 2016 at 10:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.