包的设计原则总结(四) - 稳定依赖原则(SDP)
|
介绍一下RobertC.Martin提出的面向对象的设计原则中的稳定依赖原则。参考文档(http://www.objectmentor.com/resources/articles/Principles_and_Patterns.pdf )。 稳定依赖原则(SDP):The Stable Dependencies Principle 。是为了解决包设计的依存问题的。 包之间的依赖关系都应该是稳定方向依赖的,包要依赖的包要比自己更具有稳定性。(The dependencies between packages in a design should be in the direction of the stability of the packages. A package should only depend upon packages that are more stable that it is.)。
稳定依赖原则 :稳定就是没有变化。 稳定包 : 1.自己没有依赖其他包,也就是自己一个完全独立的。 2.其他有很多包依赖于自己。依赖的包越多,自己的责任越大。 不稳定包 : 1.自己依赖其他多个包,也就是自己不是独立的。 2.没有依赖于自己的其他包。也就是自己对其他包没有责任。 不稳定度的计算公式:I=Ce/(Ce+Ca)。 例子: Ce=0(自己依赖的外部包没有)的时候,不稳定度I为0、表示该包是最为稳定的包。 SDP稳定依赖原则“Depend upon packages whose I metric is lower than yours.” 例:A依赖B的时候 如果B还不如A稳定的话,就不应该让A依赖B。 (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
