34

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

asked Dec 13, 2010 at 15:19
0

11 Answers 11

62

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.

answered Dec 13, 2010 at 15:30
Sign up to request clarification or add additional context in comments.

2 Comments

I have a query. In Java, why is Collections termed as both API as well as framework. Sometimes it is written "Collections API", and sometimes "Collections framework". Also, keeping in mind your answer, what about "Reflection API" of Java? It is face of which framework of Java?
I don't know. I also don't know.
8

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.

answered Dec 13, 2010 at 15:29

Comments

4
  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.

answered Dec 13, 2010 at 15:31

Comments

3

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

answered Dec 13, 2010 at 15:31

Comments

2
  • 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.

answered Sep 3, 2021 at 16:27

Comments

0

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:
answered Dec 13, 2010 at 15:29

Comments

0

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.

answered Dec 13, 2010 at 15:31

Comments

0
  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..

answered Aug 10, 2015 at 12:09

1 Comment

What about "Collections Framework"? Why is it termed like that?
0

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.

answered Oct 27, 2016 at 10:00

Comments

0

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.

answered Feb 24, 2017 at 7:19

Comments

0

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.

answered Jul 31, 2017 at 18:19

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.