6. More examples
• Behavior of many frameworks
– Spring framework、Android framework、EJB
framework。
• Implementation techniques
– Dependency injection、
– Factory pattern、
– Template pattern、
– Strategy pattern...etc。
7. In other words...
• Inversion of Control基本上是個高階的抽象
(不是抽象化) 概念與原則,在現代軟體開發
環境中處處可見其蹤影。
8. What is
Dependency Inversion Principle?
• 由Robert C. Martin所定義:
– High-level modules should not depend on lowlevel modules. Both should depend on
abstractions.
– Abstractions should not depend upon details.
Details should depend upon abstractions.
• 一種透過使高階元件與低階元件以抽象層
協同工作,以降低程式碼耦合度的技巧。
9. Bad design caused by high coupling
• Rigidity
– 難以對程式碼做更動;因為每一個變動都會影
響到系統中的太多地方。
• Fragility
– 當你做了一項變動,系統中某個意外的部份很
容易毀損。
• Immobility
– 元件很難以在另一個程式中再利用,因為其中
有太多與原程式纏繞的實作部分。
20. References
• Martin Fowler (2005). InversionOfControl.
• Martin Fowler (2004). Inversion of Control Containers
and the Dependency Injection pattern.
• Robert C. Martin (1996). The Dependency Inversion
Principle.
• Kyle Baley and Donald Belcham (2010). Brownfield
Application Development in .NET.
• Inversion of control. In Wikipedia. Retrieved Dec. 5
2013.
• Dependency inversion principle. In Wikipedia.
Retrieved Dec. 5 2013.
• Dependency injection. In Wikipedia. Retrieved Dec. 5
2013.