44

Now, this may be a silly question but sometimes the terms Framework and API are used interchangeably. The way I see it is that a Framework is a bigger more generic thing, containing many API's, that could be used for various programming tasks (for example, the .NET Framework.) An API is smaller and more specialized (for example, the Facebook API.) Anyone want to share their insights on the matter?

And take for instance that Microsoft call .NET a Framework whereas Sun calls theirs a Platform ... so could it be also a business/marketing decision as to how call a "collection of libraries."?

jasonco
  • 1,457
  • 1
  • 15
  • 22

12 Answers12

35

Design Patterns provide the following definitions:

  • toolkits: "often an application will incorporate classes from one or more libraries of predefined classes called toolkits. A toolkit is a set of related and reusable classes designed to provide useful, general-purpose functionality".
  • frameworks: "a framework is a set of cooperating classes that make up a reusable design for a specific class of software".

The key here is that while toolkits (APIs) can be useful in many domains, frameworks are geared to solve issues for specific classes of problems, that can be customized "by creating application specific subclasses of abstract classes of the framework".

Moreover, and maybe more importantly, "the framework dictates the architecture of your application": Inversion Of Control is one of the characteristics of frameworks (see Martin Fowler on this); instead of having your application call specific APIs to implement a specific behavior, it's the framework that calls your code.

drew moore
  • 28,107
  • 16
  • 72
  • 106
Stefano Ricciardi
  • 2,845
  • 3
  • 31
  • 40
20

I've always thought the framework was the whole thing, internal code, API's, etc.

While the API is just the bit you use when you want to make use of the framework.

In other words, the .NET framework consists of the .NET libraries, all the languages and so on. The API is just the way you call the functions.

paxdiablo
  • 772,407
  • 210
  • 1,477
  • 1,841
16

A framework does introduce the notion of inversion of control
(i.e. the overall program's flow of control is not dictated by the caller, but by the framework)

When you are referring to language frameworks (such as Java Framework or .Net Framework), you actually including more than just libraries and their APIs (which would be more limited a Software Framework if those libraries provide an inversion of control).

A Language Framework includes the development and execution environments which will call your code (to compile it or to execute it).
That is why .Net Framework is a "Framework".


Java may refer to its Frameworks (JDK, JRE) as a "Java Platform" in order to emphasize its "platform independent" programming language feature.

From About the Java Technology

A platform is the hardware or software environment in which a program runs. (including Microsoft Windows, Linux, Solaris OS, and Mac OS).
Most platforms can be described as a combination of the operating system and underlying hardware.
The Java platform differs from most other platforms in that it's a software-only platform that runs on top of other hardware-based platforms.

The Java platform has two components:

  • The Java Virtual Machine
  • The Java Application Programming Interface (API)

Java Platform

VonC
  • 1,042,979
  • 435
  • 3,649
  • 4,283
9

As its name suggests (Application Programming Interface) the API is just the interface of the framework.

mouviciel
  • 62,742
  • 10
  • 106
  • 135
6

From my understanding, an API is basically a way of interfacing with an existing app (like Facebook), whereas a framework is basically a tool for building your own app from the ground up.

mpen
  • 237,624
  • 230
  • 766
  • 1,119
  • Yes, that's my point like a specialized interfacing... not necessarily an app could be hardware too. – jasonco Apr 07 '09 at 06:50
5
  • Software Framework: Is a re-usable design for a software system (or subsystem). A software framework may include programs, code libraries, a scripting language, other software to help develop and glue together the different components of a software project. Various parts of the framework maybe exposed through an API.

  • API (Application Programming Interface): Is a set of routines( AKA methods, functions), data structures, object classes, and/or protocols provided by libraries and/or operating system services in order to support the building of applications.
    More details along with other Link to this particular topic is http://aprogrammersday.blogspot.com/2009/02/difference-between-framework-and-api.html
Naeem Akram
  • 51
  • 1
  • 1
3

API (application programming interface): like his name means, is an interface for externe programs to interact with your inter program or library without having direct access. for example, the google map API and Facebook API give you the interface to interact with their program and library without having direct access.

In the other hand:

Framework : is a collection of libraries that can help you to build an application. you can imagine the framework as a "skeleton" where the application defines the "meat", so you can't take a human skeleton to build a hors body, so you have to choose the good framework before start programing. this is why we said : You call Library. Framework calls you.

HISI
  • 3,641
  • 2
  • 24
  • 43
2

I'd like to think that an API is a subset of a framework

Rad
  • 8,221
  • 4
  • 43
  • 44
  • Yes, like a framework contains many API's. For example, the Java Platform provides the Java 2D API, which I've used to resize images. – jasonco Apr 07 '09 at 06:52
2

In my experience, a framework often includes two things (at least) that an simple API doesn't:

  • Extensibility: you can compose or subclass framework components to extend or customize its functionality.

  • Tools for code-generation, administration, or diagnostic tasks related to application development.

Bill Karwin
  • 462,430
  • 80
  • 609
  • 762
2

A framework is basically a collection of classes that abstract away the development process and promote code reuse for example you might have database, session, and pagination classes that are independent of the application you are building. But an API is source code interface that allows two or more components of different systems to interact, for example adding the Google Maps API to your website, you and Google are two different systems, Google coded the underlying interface for incorporating its products to your website/application. All in all just go with a framework work when building your system, then develop an API when you offer extensions for other people like Facebook and Google.

Kenneth
  • 21
  • 1
1

I know this is an old thread and that it really doesn't matter, but I just can't help but to chime in with my own views. An API (e.g. device driver API, Windows API, etc.) provides the basic and essential functions for a platform such that a programmer can exercise his creativity and do something with the platform - yes, including using it to build a framework. A framework is higher level in function and abstraction, and provide a set of reusable and convenient functions/classes/conventions to facilitate the development of applications that share certain common attributes (e.g. iPad apps, web services, etc.)

Hampden123
  • 1,230
  • 1
  • 14
  • 16
1

A framework implements a very important option called IoC (Inversion of Control) which means in a nutshell that your code has, no more, things in hand.

While in an API your code calls other codes (libraries), when you use a specific framework, it's the framework who is in control of the application flows.

Oussama L.
  • 1,676
  • 5
  • 23
  • 28