Yesterday, I introduced the forward engineering example code using VS2010 modeling, introduced how to model and how to export engineering files, and today we will discuss how to reverse-Engineer UML Design class diagrams from existing code.
First, we'll start by creating the project files that we're going to reverse-engineer, and the project is simple to demonstrate overall, we have set up 3 projects (class Library), as shown in the figure:
This project mainly realizes the data subtraction 4 kinds of simple computation operations, mainly in order to demonstrate how to reverse engineering and how to export the dependencies.
Here are the features of these 3 class libraries:
Zy. testmodeling.interfacedefine--The main function of this class library is the interface declaration.
Zy. testmodeling.implement--This class library is primarily responsible for the implementation of the function (the strategy pattern is used to encapsulate the algorithm).
Zy. testmodeling.ui--as the name suggests, this class library is primarily responsible for UI programs interacting with the user interface UI interface.
So our project structure is clear, below see how to use VS2010 expansion for reverse engineering.
First of all, we should create the class diagram file we need, how to operate it. That is, we right click on the solution and choose "Add"-"New Project"
Then select "Modeling Project" in the New Project dialog box to set the project name and storage location and click "OK"
This will automatically generate the modeling project under the solution
Then select the item click on the menu bar "Architecture"-"new Diagram" in Visual Studio 2010
Then pop up the new Diagram dialog box, select the UML class diagram settings name and add to the modeling project and click OK
Generates a. classdiagram file under the modeling project, which is the class diagram project file, and double-click to open the generated class diagram file.
Then, in the Visual Studio 2010 menu bar, select Architecture-Window-"architecture manager", as shown in the figure:
This will appear in the Architecture Explorer window
There are two main types of views, solution view and Class View, respectively.
Solution View architecture presentation by hierarchy project directory in solution
Class View is the architectural presentation of a class-level project directory
Here we use the solution view approach to architecture presentation, in the Subproject window, select the project you want to reverse-engineer, so that the file floating window appears on the right, where all the files for the 3 selected items are displayed, and the Type floating window appears when all the files are selected
Hold down the left mouse button to drag the selected type to the class diagram file to release the mouse button, so that our reverse engineering class diagram is generated. How simple it is.
The final result is
Here's another place to mention, in the generated class diagram can select a class right click "View Code", so you can directly switch to the class diagram of the specific implementation file, open can double-click a class diagram in a "feature" or "operation" can be directly positioned to the implementation code, This operation is really practical and convenient.
You can also generate a dependency graph, which I think is also powerful enough to show all the DLLs that are dependent on the project graphically, to show dependencies, and even to navigate to specific dependency functions.
How to use it.
Click Architecture-"Generate dependency graph" in the visual Studio 2010 menu Bar
With 5 subkeys to choose from,
by assembly,
by namespace,
by class,
by Include File,
Custom
You can build a dependency graph on your own
Here we use "by assembly" to build
After build
Click the "" button, that is, you can show the internal details, support for the child to continue to expand, I cannot help but say that Microsoft is indeed very powerful
Also, double-click the method in the diagram to directly navigate to the specific code implementation.
So our reverse engineering is done.
I hope that we can discuss and study together. I will also write some advanced applications in the future, I hope to discuss together with you.