翻译 Spring Framework 5.2.7部分基本概念要点解答疑惑--IoC控制反转/DI依赖注入是怎么一回事?

本来不想再写这些琐碎的东西,因为太耗费时间了。但后来再次看到一些hundan再次在那里JJYY误人子弟,实在令人不齿。也不知道从哪学的,还是假装自己是“大神”、自以为是的“幻想症”患者。连基本概念都搞错的两三万月薪也不知道是怎么拿的。(HR也太好糊弄了吧,也有可能比他们好点的拿五万十万以上。不过这些家伙可能会坐在流动性较大的关卡把关上)

Spring Framework 5.2.7

Core technologies: dependency injection, events, resources, i18n, validation, data binding, type conversion, SpEL, AOP.

这里很简单罗列5.2.7版本的sping framework的核心技术:

dependency injection--依赖注入

events--事件

resources--资源

i18n

validation--验证

data binding--数据绑定

type conversion--类型转换

SpEL--Spring Expression Language--Spring表达式语言

AOP--面向方面编程

Spring Framework Core technologies (核心技术)

This chapter covers the Spring Framework implementation of the Inversion of Control (IoC) principle. IoC is also known as dependency injection (DI). It is a process whereby objects define their dependencies (that is, the other objects they work with) only through constructor arguments, arguments to a factory method, or properties that are set on the object instance after it is constructed or returned from a factory method. The container then injects those dependencies when it creates the bean. This process is fundamentally the inverse (hence the name, Inversion of Control) of the bean itself controlling the instantiation or location of its dependencies by using direct construction of classes or a mechanism such as the Service Locator pattern.

以上原文大致介绍IoC原则的概念和在spring中的应用。IoC好多翻译成:控制反转,其实应该是依赖倒置。因为在OOD/OOP面向对象设计/编程中,有个就是依赖倒置原则。(所以再听到控制反转的应该可以鄙视他)而且第一句就说的很明白:

implementation of  the Inversion of Control (IoC) principle

principle:原则、准则。IoC是一个原则、准则,不是spring的技术,更别说是核心技术。官方也说了是IoC的implementation--实施、贯彻、应用。那些把IoC和DI搞混的不知道怎么搞的。更关键的是下面这一句:

IoC is also known as dependency injection (DI).

英语课过关的都知道这是什么意思。官方这一句话彻底解释了IoC和DI的关系。这么多年都过去还是一点都没有变。当年笔者看到也是这一句。 这让笔者想起当年一个“外包大厂”面试笔者的家伙(估计工资也该有一两万吧)。也是像很多网上的信口雌黄说IoC和DI是两样东西。直到现在,还有很多blog博客长篇大论的分别“解释”两者在spring中的应用。还以为是在测试人与人之间的“苟合度”。原来是真的不会。真的是无语,说实在的还是挺有意思的:)

话说回来,Spring IoC Container运行的三种方式:

constructor arguments, arguments to a factory method, or properties that are set on the object instance after it is constructed or returned from a factory method

 分别是:构造参数,工厂方法参数,或者实例化/工厂方法生成的对象的属性。其他通过看官方文档吧。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章