API is a shortcut for "Application Programming Interface".

Loosely defined, API describes everything an application programmer needs to know about piece of code to know how to use it. The idea is that the programmer knows all Signatures of classes and methods; their parameters, parameter types (or behaviour) as well as return values.

A programmer should always write against interface (API), not against implementation. This is especially important in Python. If you know a class has method subfrob(), you'd be better off with

if hasattr(obj, 'subfrob'):

instead of using isinstance(obj, SomeSpecificClass). Effectively, this is applying idiom "if it walks like a duck, quacks like a duck..." it's a duck alright. Controlling behaviour depending on class instance used is more like programming to implementation, whereas programming against "signature" is more like programming against interface.

An example of API can be found at Voicent Simple Telephone Call API. The published class is used to encapsulate the implementation details.

API (last edited 2008-11-15 14:00:23 by localhost)

Unable to edit the page? See the FrontPage for instructions.