GRASP原则八: 间接 Indirection
若两个对象直接连接,导致耦合太紧,如何解决?
3.1 GRASP rule8: Indirection 间接
Name: Indirection
Problem: 把职责分配到哪里可以避免两个或者多个对象之间的 直接耦合?如何解耦对象以保持较高的可重
用性?
Where to assign a responsibility to avoid direct coupling between two or more objects? How to
de-couple objects so that reuse potential remains higher
Solution: 把职责分配给一个中介对象,隔离对象与其他构件或 者服务,使它们不产生直接耦合
Assign the responsibility to an intermediate object to mediate between other components or services
so that they are not directly coupled
因为中介对象是一种特殊的作用,一般对象与中间对象之间的直接耦合, 相对比较简单