迪米特法则(Law of Demeter) LOD。这个原则是说我只依赖我确实需要的类,也叫最小知识原则。
这个原则的英文Each unit should have only limited knowledge about other units:only units ‘closely’ related to the current unit. Or:Each unit should only talk to its friends; Don’t talk to strangers.
依赖倒置原则(Dependency Inversion Principle)DIP。这个原则的英文是high-level modules shouldn't depend on low-level modules. both modules should depend on abstractions. In addition, abstractions shouldn't depend on details.Details depend on abstractions.。意思是高层模块不要依赖底层模块。高层模块和底层模块都应该依赖抽象。抽象不要依赖具体实现,具体实现应该依赖抽象。
这个原则的英文描述是functions that use pointers of references to base classes must be able to use objects of derived classes without knowing it。子类对象能够替换程序中父类对象出现的任何地方,并且保证原来程序的逻辑行为不变及正确性不被破坏。