首先讲了这个原则的目的是为了 decouple objects in an application by inverting 反向 certain dependencies between them.
这个原则的应用可以使代码更 robust and maintainable.
The dependency inversion principle states that:
1. High-level objects should not depend on low-level objects. Both should depend on abstractions.
2. Abstractions should not depend on details. Details should depend on abstractions.
另外在 ios-programming-the-big-nerd-ranch-christian-keur 第六版 第十章 P185 中提到的 在Homepwner这个应用当中,针对上述提到的DIP中的高层模块和底层模块分别对应于
A store is a lower-level object that retrives 检索 and save Item instances through details that are only known to that class.
ItemsViewController is a higher-level object that only knows that it will be provided with a utility object (the store) from which it can obtain a list
of Item instances and to which it can pass new or updated Item instances to be stored persistently 持久的.
This results in a decoupling because ItemsViewController is not dependent on ItemStore. In fact, as long as the store abstraction is
respected, ItemStore could be replaced by another object that fetches 获取 Item instances differently (such as by using a web service)
without any changes to ItemsViewController.
文末还提到了另外一种实现 dependency inversion principle的 a common pattern 叫做: dependency injection
... 之后再了解!