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


当前回答

已经有很多很好的答案了,但让我看看我是否能给你另一个观点。

为了简化事情,您可以将框架视为一个除了实际功能之外完整的应用程序。你插入功能和PRESTO!你有一个应用程序。

Consider, say, a GUI framework. The framework contains everything you need to make an application. Indeed you can often trivially make a minimal application with very few lines of source that does absolutely nothing -- but it does give you window management, sub-window management, menus, button bars, etc. That's the framework side of things. By adding your application functionality and "plugging it in" to the right places in the framework you turn this empty app that does nothing more than window management, etc. into a real, full-blown application.

对于web应用程序,服务器端应用程序等也有类似类型的框架。在每种情况下,框架提供了大量乏味、重复的代码(希望如此),而您提供了实际的问题域功能。(这是理想状态。当然,在现实中,框架的成功有很大的变数。)

我再次强调,这是对框架的简化观点。我没有使用像“控制反转”之类的可怕术语,尽管大多数框架都内置了这样可怕的概念。既然你是初学者,我想我就不给你行话了,用一个简单的比喻。

其他回答

一个框架帮助我们使用“已经创建的”,一个比喻可以是,

把地球上的物质想象成编程语言,

举个例子,“相机”是一个程序,你决定创建一个笔记本。你不需要每次都重新创建相机,你只需要使用earth框架(例如技术商店)将相机并将其集成到你的笔记本电脑中。

一般来说,框架作品是真实的或概念性的结构,旨在作为建筑的支撑或指南,将结构扩展为有用的东西……

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

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

I'm very late to answer it. But, I would like to share one example, which I only thought of today. If I told you to cut a piece of paper with dimensions 5m by 5m, then surely you would do that. But suppose I ask you to cut 1000 pieces of paper of the same dimensions. In this case, you won't do the measuring 1000 times; obviously, you would make a frame of 5m by 5m, and then with the help of it you would be able to cut 1000 pieces of paper in less time. So, what you did was make a framework which would do a specific type of task. Instead of performing the same type of task again and again for the same type of applications, you create a framework having all those facilities together in one nice packet, hence providing the abstraction for your application and more importantly many applications.

已经有很多很好的答案了,但让我看看我是否能给你另一个观点。

为了简化事情,您可以将框架视为一个除了实际功能之外完整的应用程序。你插入功能和PRESTO!你有一个应用程序。

Consider, say, a GUI framework. The framework contains everything you need to make an application. Indeed you can often trivially make a minimal application with very few lines of source that does absolutely nothing -- but it does give you window management, sub-window management, menus, button bars, etc. That's the framework side of things. By adding your application functionality and "plugging it in" to the right places in the framework you turn this empty app that does nothing more than window management, etc. into a real, full-blown application.

对于web应用程序,服务器端应用程序等也有类似类型的框架。在每种情况下,框架提供了大量乏味、重复的代码(希望如此),而您提供了实际的问题域功能。(这是理想状态。当然,在现实中,框架的成功有很大的变数。)

我再次强调,这是对框架的简化观点。我没有使用像“控制反转”之类的可怕术语,尽管大多数框架都内置了这样可怕的概念。既然你是初学者,我想我就不给你行话了,用一个简单的比喻。