最近收到读者反馈,《架构整洁之道》第 25 章“层次与边界”中,图 25.3 和解释这张图的一段文字的描述让人很费解。
图25.3 修正后的设计图
文字解释如下
如果我们进一步查看 GameRules 内部,就会发现 GameRules 组件的代码中使用的 Boundary 多态接口是由 Language 组件来实现的;同时还会发现 Language 组件使用的 Boundary 多态接口由 GameRules 代码实现。
读者的疑惑是 GameRules 和 Language 分别定义接口让对方实现,那么这两个组件不就形成双向依赖了吗?
我们仅凭直觉就知道双向依赖肯定是错的,那么这句话到底该作何解释?为了排除翻译出错的可能性,我仔细比照了原文,确定了译文并不损失原意。
If we were to look inside GameRules, we would find polymorphic Boundary interfaces used by the code inside GameRules and implemented by the code inside the Language component. We would also find polymorphic Boundary interfaces used by Language and implemented by code inside GameRules.