Creating Aggregation and Composition in class diagram in Visual Studio 2017

ε祈祈猫儿з 提交于 2019-12-22 05:24:15

问题


I am thinking about creating a class diagram in Visual Studio. I notice that the Toolbox only appears to allow Association relationships between classes.

Is it possible to create stronger relationships in the class diagram, i.e. Aggregation and Composition relationships?

Also, is it possible to automatically create the class diagram from the code?


回答1:


Great Question.

First of all: Visual Studio (VS) Class Designer is not a CASE Tools (like Enterprise Architect and etc.).
It is only a class representation of the source codes. Meaning that classes in class designer are always synchronized with the classes in the source code. If you delete some attributes or methods in source code, it synchronized with class designer and vise versa.

Secondly: The answer of this question hides in mapping Association and Aggregation (and Composition) to source code.

To map Associations, Aggregation and Composition to source code see: Reference 1 and Reference 2.

Detecting Association or Aggregation or Composition relationships between classes from the Source Code is impossible in some cases.

For example, what type of relationship is between Customer and Car in below code?

public class Customer {
    private String name;
    private String address;
    private String contactNumber;

    private Car car;        
}


public class Car {
    private String modelNumber;
    private Customer owner;
}

It can be Association or Aggregation.

Finally, because of first and second reasons as described above, Visual Studio Class Diagram do not have Aggregation and Composition.



来源:https://stackoverflow.com/questions/47895358/creating-aggregation-and-composition-in-class-diagram-in-visual-studio-2017

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!