翻譯 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

 分別是:構造參數,工廠方法參數,或者實例化/工廠方法生成的對象的屬性。其他通過看官方文檔吧。

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