框架和容器的区别? [英] Difference between framework and container?

查看:49
本文介绍了框架和容器的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

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?

提前致谢.

推荐答案

我认为您将控制反转的原理和 IoC 工具混淆了.

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

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

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.

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

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.

这篇关于框架和容器的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆