Introduction
I would like to share an easy way to understand Class Diagrams in C#. We will use Visual Studio 2012 to generate Class Diagrams and we have this feature in Visual Studio 2012 to generate Class Diagrams and then we will learn the procedure step by step.
Procedure
1. Create a few classes as per the screen below.
- We have added the four classes Person, Student, Emp and Customer.
- The point to be noted here is, the Person class is a general class and the ohter classes, Emp, Student and Customer, are specific classes. Furthermore we will use Person as the base class for the other classes as in the following document.
2. Right-click on the project to create a Class Diagram as per the screen below.
3. The following will be the output:
- We have a star symbol for protected members.
- We have the Lock symbol for Private members.
4. Now use inheritance as in the following:
5. Again right-click on the project to generate Class Diagrams.
Person is the base class so the following is the output.
6. We can rearrange these boxes in the proper manner. These boxes can be dragged and dropped.
7. Now we will use Interface as in the following:
8. Diagram for Interface:
9. Using Interface1 in classes:
10. Now create a diagram as in Step 2.
11. Right-click on the box to see its properties.
12. Right-click on the inheritance line to see the details.
Conclusion
We have learned how to create a Class Diagram using Visual Studio 2012.