Dependency Injection(DI) and Inversion of Control(IoC)

Dependency Injection(DI):

DI flavor of Inversion of Control. The Inversion of Control(IoC) is a general concept, and it can be expressed in many different ways and Dependency Injection is merely one concrete example of Inversion of Control.
Dependency Injection helps in gluing these classes together and same time keeping them independent.
Dependency injection can happen in the way of passing parameters to the constructor or by post-construction using setter methods.

Inversion of Control(IoC)

優(yōu)缺點(diǎn)
優(yōu)點(diǎn):
把對(duì)象生成放在了XML里定義,使換一個(gè)實(shí)現(xiàn)子類變得很簡(jiǎn)單(用于實(shí)現(xiàn)某種接口的對(duì)象), 只要修改XML就可以,甚至可以實(shí)現(xiàn)對(duì)象的熱插拔。
缺點(diǎn):
1)生成對(duì)象步驟變復(fù)雜
2)使用反射編程,效率損耗。(損耗<提高的靈活性和維護(hù)性)
3)缺少IDE重構(gòu)操作支持

實(shí)現(xiàn)方式:
實(shí)現(xiàn)數(shù)據(jù)訪問(wèn)層
模塊與接口重構(gòu)
隨時(shí)增加單元測(cè)試
使用服務(wù)定位器而不是構(gòu)造注入

Spring Architecture


Image.png
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 文章作者:Tyan博客:noahsnail.com 2.Introduction to the Spring Fr...
    SnailTyan閱讀 5,543評(píng)論 7 56
  • 文章作者:Tyan博客:noahsnail.com 3.4 Dependencies A typical ente...
    SnailTyan閱讀 4,518評(píng)論 2 7
  • 等了四十七年的親情,相見(jiàn)時(shí)沒(méi)有陌生,沒(méi)有代溝,沒(méi)有分窮富;而這一切親密無(wú)間的人情味,源于上輩血脈因源。 每一家的血...
    子興閱讀 530評(píng)論 0 12
  • 那一瞬,我定格在你瘦高的身軀,便知此生與你有不盡的塵緣。 那一刻,我望盡黑夜燈火,終于迎來(lái)與你溫柔一遇。 那一夜,...
    蘭因素果閱讀 172評(píng)論 0 0
  • 烏云遮日久不開, 杏花引得蜜蜂來(lái)。 午后春日三月里, 冬剛唱霸春登臺(tái)。
    五月秋色閱讀 263評(píng)論 0 1

友情鏈接更多精彩內(nèi)容