UML:可见性指南
UML: guideline for visibility
我正在阅读 Real Time UML: Advances in the UML for Real-Time Systems (3rd Edition) 第 3 版
作者:布鲁斯·鲍威尔·道格拉斯
在第 10.5 节中谈到有关可见性详细设计的指南时。他说:
只使语义上适当的操作可见。
This guideline
seeks to avoid pathological coupling among classes. For example,
suppose a class is using a container class. Should the operations be
GetLeft() and GetRight() or Prev() and Next()? The first pair makes
the implementation visible (binary tree) while the latter pair
captures the essential semantics (ordered list).
我无法理解他在这里想说什么,尤其是最后一行。
有人可以详细说明他的观点吗?
嗯,有点微妙。 GetLeft
和 -Right
的名称中包含方向,这些方向源自二叉树的内部实现。所以内部数据结构在界面中是可见的。事实并非如此。出于多种原因,最好将这些知识保留在内部。首先,外部世界必须不关心事情是如何实施的。其次,如果您决定以不同的方式实现它(例如通过环形缓冲区),如果您到达缓冲区的右边界,从内部视图来看 GetRight
会很奇怪。 Prev
和 Next
明确针对操作的 business/outer 使用方面。
我正在阅读 Real Time UML: Advances in the UML for Real-Time Systems (3rd Edition) 第 3 版 作者:布鲁斯·鲍威尔·道格拉斯
在第 10.5 节中谈到有关可见性详细设计的指南时。他说:
只使语义上适当的操作可见。
This guideline seeks to avoid pathological coupling among classes. For example, suppose a class is using a container class. Should the operations be GetLeft() and GetRight() or Prev() and Next()? The first pair makes the implementation visible (binary tree) while the latter pair captures the essential semantics (ordered list).
我无法理解他在这里想说什么,尤其是最后一行。
有人可以详细说明他的观点吗?
嗯,有点微妙。 GetLeft
和 -Right
的名称中包含方向,这些方向源自二叉树的内部实现。所以内部数据结构在界面中是可见的。事实并非如此。出于多种原因,最好将这些知识保留在内部。首先,外部世界必须不关心事情是如何实施的。其次,如果您决定以不同的方式实现它(例如通过环形缓冲区),如果您到达缓冲区的右边界,从内部视图来看 GetRight
会很奇怪。 Prev
和 Next
明确针对操作的 business/outer 使用方面。