框架和容器的区别?

发布于 2024-12-02 22:23:29 字数 410 浏览 1 评论 0原文

我正在阅读这个问题: 框架与工具包与库 哪里解释了框架和库之间的区别。一般认为,主要区别在于控制反转,因此您在框架中存在热点,您可以在其中附加应用程序功能(实质上您可以在继承/模板/重量级或组合/策略/轻量级之间进行选择来实现这一点)。

好吧,现在我很好奇框架和容器有什么区别?我看到了以下容器的定义(由 Rod Johnson 编写):“容器是应用程序代码/对象在其中运行的框架”。这就是让我困惑的地方。我认为这或多或少是任何框架的定义:)我的意思是,如果你使用 IoC 作为参数来区分库和框架(又名你调用库,但框架调用你),那么这是否意味着更多或者更少的框架满足上述容器的定义?

提前致谢。

I was reading this question on SO:
Framework vs. Toolkit vs. Library
where is explained difference between framework and library. General opinion is that main difference is in Inversion of Control, so you have hot spots in framework where you attach your application functionality (in essence you choose between inheritance/template/heavyweight or composition/strategy/lightweight to achieve that).

Ok, now I am curious what is difference between framework and container then? I saw following definition of container (by Rod Johnson): "Container is framework in which application code/objects runs". And that is what confused me. I thought that it is more or less definition of any framework :) I mean, if you use IoC as parameter that makes difference between library and framework (aka you call library, but framework calls you), then doesn't it mean that more or less any framework satisfy above definition of container?

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

半仙 2024-12-09 22:23:29

我认为你混淆了控制反转的原理和 IoC 工具。

框架的主要特征是它遵循 IoC 原则并调用您的代码(如链接线程中所述)。
IoC 容器只是一个工具,而不是一个成熟的框架,可以帮助您按照 IoC 原则编写内聚的、松散耦合的代码。

一般来说(至少在 .Net 中),类 Container 是该工具的基础,其中发生注册/解析/构建对象图等,但我相信该名称是基于 PicoContainer 名称和 Martin Fowlers 文章 控制容器反转和依赖注入模式

I think you are mixing up the principle of Inversion of Control and an IoC tool.

The main characteristic of a framework is that it follows the IoC principle and calls your code (as explained in the linked thread).
An IoC container is merely a tool, not a fullblown framework, to aid you to write cohesive, loosely coupled code following the IoC principle.

In general (at least in .Net) a class Container underlies this tool where the registration/resolving/building up object graph etc. takes place but i believe the name is an historical artifact based on the name PicoContainer and Martin Fowlers article Inversion of Control Containers and the Dependency Injection pattern.

番薯 2024-12-09 22:23:29

容器是操作系统和代码的完整封装,使用户或执行模型能够运行。框架包含特定过程所需的所有代码。(就像在Python中,如果我们想创建训练测试数据集,我们有来自sklearn的内置代码)。

Container is full package of os and codes which enables the user or execution model to run. Framework contains all the code needed for particular process.(like in python if we want to create the train test dataset,we have inbuilt code from sklearn).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文