Isolating complexity in places that are rarely interacted with is roughly equivalent to eliminating complexity.
改变软件设计的时候,修改的代码越少,软件的复杂性越低。
Reduce the amount of code that is affected by each design decision, so design changes don't require very many code modifications.
复杂性尽量封装在模块里面,不要暴露出来。如果多个模块耦合,那就把这些模块合并成一个。
When a design decision is used across multiple modules, coupling them together.
三、接口和实现
模块分成接口和实现。接口要简单,实现可以复杂。
Modules are interface and implementation. The best modules are where interface is much simpler than implementation.
It's more important for a module to have a simple interface than a simple implementation.
好的 class 应该是"小接口,大功能",糟糕的 class 是"大接口,小功能"。好的设计是,大量的功能隐藏在简单接口之下,对用户不可见,用户感觉不到这是一个复杂的 class。
最好的例子就是 Unix 的文件读写接口,只暴露了5个方法,就囊括了所有的读写行为。