Framework Vs. API

2019-01-16 03:34发布

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."?

12条回答
姐就是有狂的资本
2楼-- · 2019-01-16 04:11
  • 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
查看更多
别忘想泡老子
3楼-- · 2019-01-16 04:13

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

查看更多
倾城 Initia
4楼-- · 2019-01-16 04:15

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.

查看更多
小情绪 Triste *
5楼-- · 2019-01-16 04:15

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.

查看更多
祖国的老花朵
6楼-- · 2019-01-16 04:18

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

查看更多
仙女界的扛把子
7楼-- · 2019-01-16 04:18

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

查看更多
登录 后发表回答