Viewing the Associated Code
When you create a class in the Class Designer, Visual Studio automatically creates the associated code file. As you make changes in the Class Designer, the changes are immediately reflected in the code. This makes it easy for you to go back and forth between the designer view and the code view.
|If you are using C#, the Class Designer provides many features to assist you with refactoring your application.|
In the past, most visual tools performed a round trip to keep your diagrams in synch with your code. The tool would perform one trip to convert a diagram into code. If changes were then made to the code, the tool would require a return trip to convert the code back to a diagram, hence the term round trip
. But these conversions often resulted in loss of detail as the tool converted back and forth between code and the diagram.
The Class Designer does not perform a round trip. It does not actually "trip" at all. Rather, it is simply another view of the same data. This means that you don't lose any detail as you go from code to designer and back to code.
As an example, the code view for the Order class created in the Class Designer is as follows:
Public Class Order
Public Property OrderDetail() _
Set(ByVal value As OrderBO.OrderDetail)
''' This function calculates the total amount of
''' the order, including shipping and taxes.
Private Function CalculateTotal() As Double
If you change this code?the diagram will change accordingly. For example, you can add a new method to the class in the code view as follows:
Private Function CheckInventory() As Boolean
The new method is immediately shown in the diagram as illustrated in Figure 4
|Figure 4: Changes made to the Class Design are automatically reflected in the code and visa versa.|
So you can use whichever view is best for you. For example, you can create the classes with the Class Designer and then edit them in the Code Editor. Either way, the code will be correct in both views.
Working with Existing Code
In many cases, you spend a large portion of your time working with existing code?not creating new code. The Class Designer has features to help you with that as well.
You can open any project with Visual Studio 2005, create a Class Designer, and then drag classes from the Solution Explorer or the Class View window to the designer surface. Try this with an existing project. Be sure to create a backup of it first if you are converting from an existing Visual Studio 2003 project.
You can also refactor existing code with the Class Designer. Refactoring
is the process of changing your application in such a way that it does not change how it works, but rather it improves the internal structure of the application. Refactoring is often necessary if a section of the application has been changed frequently and is no longer easy to understand or maintain.
If you are using C#, the Class Designer provides many features to assist you with refactoring your application. You can rename identifiers, extract interfaces, and convert simple fields to properties.
The Class Designer is a great tool for visualizing your application. Use it when working with existing code to view the class structure and their relationships. Use it to graphically create new classes or edit existing classes. Or use it to refactor your application. The only down side is that we have to wait for Visual Studio 2005 to see all of these benefits.
Note that the Class Designer is part of Visual Studio Team System for architects and developers. Team System is expected to be available in the Enterprise edition of Visual Studio only.