简体   繁体   English

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

[英]In a UML Class diagram, how do you specify Actual type of a class?

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[*]. 为了使设计尽可能灵活,我想使用自定义“ TableDataGetter”接口获取决策树数据,该接口包含方法getData():String [*]。 In my particular implementation, I want to use a class "TextTableDataGetter" which implements "TableDataGetter". 在我的特定实现中,我想使用实现“ TableDataGetter”的类“ TextTableDataGetter”。

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. 如果我的理解是正确的,则在UML类图中显示的方法是使用决策树类和“ TableDataGetter”接口之间的组合关系。

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? 我的问题是,在绘制图表时,是否要指定要使用“ TextTableDataGetter”,如何用标准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. 我想在图上尽可能具体,因为我正在集思广益,让UML软件为我生成代码。 I want to be sure, that in the decision tree class I have my dataGetter variable declared as "TableDataGetter dataGetter = new TextTableDataGetter()" 我想确定的是,在决策树类中,我的dataGetter变量声明为“ TableDataGetter dataGetter = new TextTableDataGetter()”

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. 例如,事务“具有”事务ID号,并且该事务是唯一具有该事务ID号的事务,该ID号是该事务专用的。 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. 在UML类图上绘制这两种关系类型时,组成关系将用实心菱形表示,聚合关系将用未填充的菱形表示。

替代文字

The book Introduction to Java Programming covers this subject in great detail. Java编程简介 》一书详细介绍了该主题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM