Browse DevX
Sign up for e-mail newsletters from DevX


Visualize Your Code with the Class Designer : Page 2

The Class Designer in Visual Studio 2005 allows you to visually manipulate the classes of your application. Changes made to the diagram are reflected in the associated code. Get a tour of this new feature.




Building the Right Environment to Support AI, Machine Learning and Deep Learning

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() _ As OrderBO.OrderDetail Get End Get Set(ByVal value As OrderBO.OrderDetail) End Set End Property ''' <summary> ''' This function calculates the total amount of ''' the order, including shipping and taxes. ''' </summary> Private Function CalculateTotal() As Double End Function End Class

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 End Function

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.

Deborah Kurata is cofounder of InStep Technologies Inc., a professional consulting firm that focuses on turning your business vision into reality using Microsoft .NET technologies. She has over 15 years of experience in architecting, designing, and developing successful .NET applications. Deborah is the author of several books, including "Doing Objects in Visual Basic 6.0" (SAMS) and "Doing Web Development: Client-Side Techniques" (APress). She is on the INETA Speaker's Bureau and is a well-known speaker at technical conferences.
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date