Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating Aggregation and Composition in class diagram in Visual Studio 2017

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?

like image 695
w0051977 Avatar asked Dec 19 '17 21:12

w0051977


People also ask

How do you add aggregation to a class diagram?

To show aggregation in a diagram, draw a line from the parent class to the child class with a diamond shape near the parent class. To show aggregation in a diagram, draw a line from the parent class to the child class with a diamond shape near the parent class.

How do you create a class diagram from a project in Visual Studio 2017?

Install the Class Designer component Visual Studio Installer opens. Select the Individual components tab, and then scroll down to the Code tools category. Select Class Designer and then select Modify. The Class Designer component starts installing.

Can you explain aggregation and composition in class diagrams?

Aggregation implies a relationship where the child can exist independently of the parent. Example: Class (parent) and Student (child). Delete the Class and the Students still exist. Composition implies a relationship where the child cannot exist independent of the parent.


1 Answers

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.

like image 55
Gholamali-Irani Avatar answered Oct 07 '22 15:10

Gholamali-Irani