谁能给我解释一下什么是软件框架?为什么我们需要一个框架?框架做了什么来简化编程?


当前回答

我不确定“框架”是否有一个明确的定义。有时,一组很大的库被称为框架,但我认为这个词的典型用法更接近于aioobe带来的定义。

这篇非常好的文章总结了一组库和一个框架之间的区别:

框架可以定义为一组库,它们说“不要给我们打电话,我们会给你打电话”。

框架如何帮助您?因为您不需要从头开始编写一些东西,基本上只需扩展一个给定的工作应用程序。通过这种方式,您可以获得很高的生产率——有时最终得到的应用程序可能比您在相同时间内自己所做的要复杂得多——但您通常会牺牲很多灵活性。

其他回答

除了定义(有时只有在你已经理解的情况下才能理解)之外,还有一个例子帮助了我。

I think I got a glimmer of understanding when loooking at sorting a list in .Net; an example of a framework providing a functionality that's tailored by user code providing specific functionality. Take List.Sort(IComparer). The sort algorithm, which resides in the .Net framework in the Sort method, needs to do a series of compares; does object A come before or after object B? But Sort itself has no clue how to do the compare; only the type being sorted knows that. You couldn't write a comparison sort algorithm that can be reused by many users and anticipate all the various types you'd be called upon to sort. You've got to leave that bit of work up to the user itself. So here, sort, aka the framework, calls back to a method in the user code, the type being sorted so it can do the compare. (Or a delegate can be used; same point.)

我算对了吗?

框架为特定的问题领域提供功能/解决方案。 定义来自wiki:

计算机中的一个软件框架 编程,是一种抽象 哪个公共代码提供泛型 功能可以选择性地 由用户代码覆盖或专门化 提供特定的功能。 框架是一种特殊情况 它们是软件库 代码包装的可重用抽象 在定义良好的应用程序中 编程接口(API),然而他们 包含一些关键区别 区分它们的特征 普通的图书馆。

框架具有您可能需要的一些功能。您可能需要某种具有内置排序机制的数组。或者,您可能需要一个窗口,您想在其中放置一些控件,所有这些都可以在框架中找到。这是一种跨越你自己作品框架的作品。

编辑: 好吧,我将要挖掘你们试图告诉我的东西;)你可能没有注意到“跨越一个框架的工作……”这行之间的信息。 在它越陷越深之前。我试着给它一个地板,希望你优雅地: 我在这里找到了一个很好的解释“库和框架的区别”的问题 http://ifacethoughts.net/2007/06/04/difference-between-a-library-and-a-framework/

一个简单的解释是:框架是一个可以围绕它构建应用程序的支架。

A framework generally provides some base functionality which you can use and extend to make more complex applications from, there are frameworks for all sorts of things. Microsofts MVC framework is a good example of this. It provides everything you need to get off the ground building website using the MVC pattern, it handles web requests, routes and the like. All you have to do is implement "Controllers" and provide "Views" which are two constructs defined by the MVC framework. The MVC framework then handles calling your controllers and rendering your views.

也许不是最好的措辞,但我希望它有帮助

我不确定“框架”是否有一个明确的定义。有时,一组很大的库被称为框架,但我认为这个词的典型用法更接近于aioobe带来的定义。

这篇非常好的文章总结了一组库和一个框架之间的区别:

框架可以定义为一组库,它们说“不要给我们打电话,我们会给你打电话”。

框架如何帮助您?因为您不需要从头开始编写一些东西,基本上只需扩展一个给定的工作应用程序。通过这种方式,您可以获得很高的生产率——有时最终得到的应用程序可能比您在相同时间内自己所做的要复杂得多——但您通常会牺牲很多灵活性。