在 UML 类图中,如何指定类的实际类型?

发布于 2024-10-01 05:52:44 字数 428 浏览 3 评论 0原文

我正在编写一个决策树类。为了保持设计尽可能灵活,我想使用自定义“TableDataGetter”接口获取决策树数据,其中包含方法 getData():String[*]。在我的特定实现中,我想使用实现“TableDataGetter”的类“TextTableDataGetter”。

如果我的理解是正确的,那么在 UML 类图中显示的方式是使用我的决策树类和“TableDataGetter”接口之间的组合关系。

我的问题是,如果在绘制图表时,我想指定我想使用“TextTableDataGetter”,我该如何在标准 UML 中编写它?

我想在我的图表上尽可能具体,因为当我集思广益时,我让 UML 软件为我生成代码。我想确定,在决策树类中,我将 dataGetter 变量声明为“TableDataGetter dataGetter = new TextTableDataGetter()”

I am writing a decision tree class. In order to keep the design as flexible as possible I want to get the decision trees data using a custom "TableDataGetter" interface, which contains the method getData():String[*]. In my particular implementation, I want to use a class "TextTableDataGetter" which implements "TableDataGetter".

If my understanding is correct, the way to display with in UML Class diagrams is to use the composition relation between my decision tree class and the "TableDataGetter" interface.

My question is if, on the time of drawing the diagram, I want to specify I want to use the "TextTableDataGetter", how do I write this in standard UML?

I want to be as specific as possible on my diagram since I am having the UML software generate the code for me, as I brainstorm. I want to be sure, that in the decision tree class I have my dataGetter variable declared as "TableDataGetter dataGetter = new TextTableDataGetter()"

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

秋日私语 2024-10-08 05:52:44

我在此处回答了类似的问题,答案如下。

聚合和组合都表示“有”关系。两者之间的区别在于,组合指的是独占所有权。例如,交易“具有”交易ID号,并且该交易是具有该交易ID号的唯一交易,该ID号对于该交易是专有的。交易也“具有”交易日期,但许多交易也可能具有相同的交易日期。由于交易日期可以在多个交易之间共享,因此它不是排他性的。

当您在 UML 类图上绘制这两种关系类型时,组合关系将用填充的菱形表示,而聚合关系将由未填充的菱形表示。

alt text

本书 简介Java 编程 非常详细地介绍了这个主题。

I answered a similar question here, same answer below.

Both aggregation and composition represent "has a" relationships. The difference between the two is that composition refers to exclusive ownership. For instance, a transaction "has a" transaction ID number, and that transaction is the only transaction that has that transaction ID number, the ID number is exclusive to the transaction. A transaction also "has a" transaction date, but many transaction might also have that same transaction date. Since the transaction date can be shared among multiple transactions it is not exclusive.

When you are drawing these two relationship types on a UML class diagram a composition relationship would be represented with a filled in diamond where a aggregation relationship would be represented by a diamond which is not filled in.

alt text

The book Introduction to Java Programming covers this subject in great detail.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文