Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What exactly is "interface based programming"?

Tags:

I often hear/read about interfaced based programming but I am not exactly clear on what that really means. Is interfaced based programming an actual stand alone topic that actually has books written about it? If so, can anyone recommend any good ones?

I came across interface based programming as I was reading about how good APIs are designed and would like to learn more about it. Right now I am not clear how to properly go about designing an API around interfaces.

Any info is greatly appreciated.

like image 891
Flack Avatar asked Dec 04 '09 17:12

Flack


2 Answers

It's basically a matter of expressing your dependencies in terms of interfaces instead of concrete classes (or worse, static methods). So if one of your classes needs to perform authentication, it should be provided an IAuthenticator (or whatever).

This means that:

  • You can write your code before implementing the real dependency
  • You can test via mocking really easily (without having to mock classes, which gets ugly)
  • It's clear what you depend on in terms of the API instead of implementation (i.e. you have looser coupling)
like image 120
Jon Skeet Avatar answered Oct 03 '22 10:10

Jon Skeet


See if these very popular discussions help:

What is the best analogy to help non-oop developers grok interface based programming?

Why would I want to use Interfaces?

When are interfaces needed?

When should one use interfaces?

What is the purpose of interfaces?

Good Case For Interfaces

What does it mean to “program to an interface”?

like image 44
DOK Avatar answered Oct 03 '22 09:10

DOK