IOC & DI

控制反轉 & 依賴注入

由於使用這東西有一段時間了...

昨天晚上與同好們的例會結束後...

知道了這東西是有個名字的...

所以在下立馬就來寫一個啦!!

以免哪天自己忘了= =

首先我們先建立一個interface叫做Doctor

接著開始實做這個Doctor

最後...主角登場了!!

到底Doctor的夥伴是誰呢!?

當我傳入第10任Doctor時,所得到的夥伴就是Rose Tyler....

以此類推....

控制反轉(Inversion of Control,縮寫為IoC),是物件導向編程中的一種設計原則,可以用來減低電腦代碼之間的耦合度。其中最常見的方式叫做依賴注入(Dependency Injection,簡稱DI),還有一種方式叫「依賴尋找」(Dependency Lookup)。通過控制反轉,物件在被建立的時候,由一個調控系統內所有物件的外界實體,將其所依賴的物件的參照傳遞給它。也可以說,依賴被注入到物件中。

文字詳請請見 維基百科

也可以參考 The Will Will Web 的 Unity Application Block 與 ASP.NET MVC 學習資源整理

 

We all change, when you think about it, we're all different people; all through our lives, and that's okay, that's good, you've gotta keep moving, so long as you remember all the people that you used to be. I will not forget one line of this, not one day, I swear.