Preparation
In order to follow and complete this tutorial, you must have Visual Paradigm installed, which can be downloaded from Visual Paradigm download page. Of course, you need Visual Studio ready, and with Visual Studio integration installed in advance. Finally, to make the tutorial easier to follow we are not going to describe every little step required to draw a class diagram in detail. We are assuming that you have the basic skills required to draw UML class diagram in Visual Paradigm.
Design system with UML Class Diagram
- Create a C# library project Map Viewer in Visual Studio.
- Right-click on the project node in Solution Explorer, and select Open Visual Paradigm from the popup menu.
- In Diagram Navigator, right-click on class diagram and select New Class Diagram from the popup menu.
- A new diagram is created. You are asked to enter a package header on top of the diagram. Enter myapp and press Enter. From now on classes to be drawn in this diagram will be placed in a (new) package named myapp. In code level, those classes will be in myapp namespace.
- Click on the down arrow button near the shape selection Class in diagram toolbar, and select Interface.
- Click on the diagram to create an interface class and name it as IMap.
- Create operations in IMap. Right-click on the class IMap and select Add > Operation from the popup menu.
- Enter JumpToLocation(x:int, y:int): void to create a public operation JumpToLocation with parameter x, y and return void.
- Press Enter to create another operation, Name it Clear() : void. Click on diagram to confirm editing.
- We need to create a class for town map which inherits IMap. Move the mouse pointer over interface IMap, press on the Resource Catalog icon and drag it out.
- Release your mouse button on the empty space. Select Realization -> Class from Resourece Catalog to create a new class.
- Name the class as TownMap and press Enter to confirm.
- As the TownMap class is implementing the interface IMap, we need to implement the operations defined in IMap. Right-click on class TownMap and select Related Elements > Realize all Interfaces from the popup menu. You can see that operations JumpToLocation and Clear are both inherited.
- It is time to add properties to class. Right-click on class TownMap and select Add > Property from the popup menu.
- Enter name : string to name the property as name, and set the type as string. Press Enter to proceed to the next property. Enter x : double as property name and type. Then, press Enter and create property y : double.
- We need to create a new class Region with an aggregation (association) from class TownMap. Again, use Resource Catalog to create a class from TownMap. This time, use the resource Aggregation -> Class.
-
Follow the previous steps to create properties in class Region.
Class Properties Region name : string desc : string x : double y : double - Up to now, the diagram should look like:
UML to C# code generation in Visual Studio
- Save your work via the File menu.
- Now comes the code generation. Select the menu Update Code on Diagram Navigator.
- Check the Solution Explorer. You should see a list of generated file. You can open them to fill in the code body.
- This is the end of the tutorial. Instead of closing Visual Studio now, you may try something more by editing the code like to add, rename or delete class, properties and operations, and select Update UML Model from Diagram Navigator, and observe the changes that will make in the class model. Enjoy!