rookie
rookie

Reputation: 7883

difference between API and framework

what is the difference between these two terms, thanks in advance for any good simplifications and good examples.

Upvotes: 34

Views: 37763

Answers (11)

Muhammad Elnawam
Muhammad Elnawam

Reputation: 31

  • API "Application Programming Interface" is set of prewritten packages, classes and interfaces with their respective methods. You can use it without much concern about internal implementations. API is used an interface between two or more applications and like REST API.

  • Framework is a skeleton that contains design patterns, classes, interfaces and libraries that can be used to build applications. Framework provides inversion of control which give the responsibility of program flow to the framework itself, also we can extend the framework without changing its predefined code. For example Spring is a framework that can be used to build web applications.

Upvotes: 2

Mike Robinson
Mike Robinson

Reputation: 8965

Another way to visualize it is this: (true of any programming language)

Any(!) "piece of software that is intended to be used by another piece of software" by-definition must have some "application program interface (API)," which represents the "knobs, switches and dials" that the other piece of software is expected (and, permitted) to use. All of the internal implementation details are not visible and cannot be reached.

"Frameworks" are tools that are designed to make it easier for humans to write a particular, common, type of application – such as a web-page. The framework implements "the stuff that every such application is going to need to be able to do," and does it in one, well-tested way, "precisely so that you (the application author) don't have to." Instead of redundantly writing "the same old thing, one more time, and fretting over whether you did it correctly," you simply leverage what the framework has already done for you.

After all...

Actum Ne Agas: Do Not Do A Thing Already Done.

Upvotes: 0

Satyam
Satyam

Reputation: 771

The main or core difference beteen framework and API is that framework allows developer to hook into the life cycle of the objects through lifecycle callback methods mechanism whereas API doesn't do that, API is only intended to perform a functionality only.

Upvotes: 0

Ghassen BHS
Ghassen BHS

Reputation: 21

An API is simply a library built with a particular language that developers can use to build applications. Frameworks are a set of libraries, just like APIs however the syntaxes may deffer of the original language. So the developer may be writing a different syntax of PHP for example when using Symphony.

Upvotes: 0

Ashish Gojiya
Ashish Gojiya

Reputation: 1

  1. Java API simply means ...Application Programming Interface in which all the features describes of product or software.

  2. Java Framework means semi-completed project or code. It provides an architecture to make project . Framework have own classes and methods etc..

Upvotes: 0

user1228
user1228

Reputation:

A framework is a group of classes, interfaces and other pre-compiled code upon which or by the use of which applications can be built.

The API is the public face of a framework. A well designed framework only exposes those classes, interfaces, etc that are needed to use the framework. Code that supports the operation of the framework but that is not necessary to users of the framework is kept internal to the framework's assemblies/dlls. This keeps the public face of the framework small and encourages a "pit of success," or the quality of a framework which makes it simple to do the right thing.

(I provide an example from the .NET world) The SqlConnection class is used to connect to a Sql Server instance. Its public API is pretty simple:

using (SqlConnection connection = new SqlConnection(connectionString))
{
    connection.Open();
    // Do work here; connection closed on following line.
}

However, this class depends on around 200 methods within the System.Data framework (in this case, an assembly), 3/4 of which are internal and not part of the public API of System.Data. Because the framework's API is kept simple, it becomes easy to use SqlConnection properly. If the user was required to deal with SqlConnectionFactory, SqlDebugContext, DbConnectionPoolGroup or any of the other internal classes required by the SqlConnection class, it would become exponentially more difficult to use SqlConnection properly. Because the API only exposes a small percentage of the framework, it is easier to create and use a connection.

Upvotes: 62

darioo
darioo

Reputation: 47193

  1. API - application programming interface -> the contract you must obey when using a library's API
  2. library - a set of classes/modules that solve a specific problem -> has an API
  3. framework - a "bigger" set of libraries with a set of rules on how to use them

Since every library has an API, no point in giving examples.

A popular Java library for time is Joda time.

A popular Java framework is the Spring framework.

You must obey a lot of rules to use Spring well. You don't have to obey as many rules to use Joda time.

Upvotes: 4

kindall
kindall

Reputation: 184270

An API is something code has, not something it is. A framework has an API, but it is not itself an API.

Upvotes: 3

Pieter
Pieter

Reputation: 2239

Framework is use to design an application, ie MVC, MEF. Like a model that you build on, almost a base for a certain set of functionality that you might want in your application.

API is for interaction between applications, your app would use the Facebook API to interact with Facebook.

Hope this is a bit more clear.

Upvotes: 0

Neilvert Noval
Neilvert Noval

Reputation: 1695

API's are pre-built-in from SDK (or from which you can include on to). Frameworks are loadable bundles wherein exposed functions of such bundles can be used. You can acquire expose functions of those frameworks by using pointer to functions.

Example:

API:

-stringWithString:

function from framework:

-myExposedMethod:

Upvotes: 0

Vincent Mimoun-Prat
Vincent Mimoun-Prat

Reputation: 28551

An API is an interface to a (set of) component(s) encapsulating a functionality. For instance, the GoogleMaps API, the DirectX or OpenGL APIs.

A framework is more a set of tools, components aimed at helping the developer to develop his/her project in a given Frame. The framework usually sets some coding standards, provides useful components, ... For instance, Symfony/Cake are PHP web application frameworks. JUnit is a framework for unit tests in Java, ...

Frameworks can often bundle/provide a unified interface to some APIs.

Some APIs can be internally built using a framework.

Upvotes: 8

Related Questions