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

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

问题描述

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

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天全站免登陆