Explicit Dependencies Principle The Explicit Dependencies Principle states: Methods and classes should explicitly require (typically through method parameters or constructor parameters) any collaborating objects they need in order to function correct…
The Stable Dependencies Principle states that “The dependencies between software packages should be in the direction of the stability of the packages. That is, a given package should depend only on more stable packages.” Whenever a package changes, a…
注:以下图片均来自<如何向妻子解释OOD>译文链接:http://www.cnblogs.com/niyw/archive/2011/01/25/1940603.html <How I explained OOD to my wife> 原文链接:http://www.codeproject.com/Articles/93369/How-I-explained-OOD-to-my-wife S.O.L.I.D 是面向对象设计(OOD)和面向对象编程(OOP)中的几个重要编…
在面向对象的设计中有很多流行的思想,比如说 "所有的成员变量都应该设置为私有(Private)","要避免使用全局变量(Global Variables)","使用运行时类型识别(RTTI:Run Time Type Identification,例如 dynamic_cast)是危险的" 等等.那么,这些思想的源泉是什么?为什么它们要这样定义?这些思想总是正确的吗?本篇文章将介绍这些思想的基础:开放封闭原则(Open Closed Princi…
最少知识原则(Least Knowledge Principle),或者称迪米特法则(Law of Demeter),是一种面向对象程序设计的指导原则,它描述了一种保持代码松耦合的策略.其可简单的归纳为: Each unit should have only limited knowledge about other units: only units "closely" related to the current unit. 每个单元对其他单元只拥有有限的知识,只了解与当前单元紧密…
单一职责原则(SRP:The Single Responsibility Principle) 一个类应该有且只有一个变化的原因. There should never be more than one reason for a class to change. 为什么将不同的职责分离到单独的类中是如此的重要呢? 因为每一个职责都是一个变化的中心.当需求变化时,这个变化将通过更改职责相关的类来体现. 如果一个类拥有多于一个的职责,则这些职责就耦合到在了一起,那么就会有多于一个原因来导致这个类的变…