18.1. Creating a Class Diagram

The design process for an application typically involves at least a sketch of the classes that are going to be created and how they interact. Visual Studio 2008 provides a design surface, called the Class Designer, onto which classes can be drawn to form a class diagram. Fields, properties, and methods can then be added to the classes, and relationships can be established among classes. Although this design is called a class diagram, it supports classes, structures, enumeration, interfaces, abstract classes, and delegates.

Before you can start working with a class diagram, you need to add one to the project. This can be done by adding a new Class Diagram to a project as shown in Figure 18-1, selecting the View Class Diagram button from the toolbar in the Solution Explorer window, or right-clicking a project or class and selecting the View Class Diagram menu item. The new Class Diagram option will simply create a new blank class diagram within the project.

Figure 18.1. Figure 18-1

A class diagram using the menu items on the Solution Explorer can behave in different ways, depending on whether a project or a class was highlighted. If the project was selected and an existing diagram does not exist in the project, the Class Designer will automatically add all the types defined within a project to the initial class diagram. Although this may be desirable, for a project that contains a large number of classes, the process of creating and manipulating the diagram can be quite time consuming.

Unlike some tools that require all types within a project to be on the same diagram, the class diagram can include as many or as few of your types as you want. This makes it possible to add multiple class diagrams to a single solution.

The scope of the Class Designer is limited to a single project. You cannot add types to a class diagram that are defined in a different project, even if it is part of the same solution.

The Class Designer can be divided into four components: the design surface, the Toolbox, the Class Details window, and the property grid. Changes made to the class diagram are saved in a .cd file, which works in parallel with the class code files to generate the visual layout shown in the Class Designer.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.217.150.123