Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Mastering UML with Rational Rose 2002.pdf
Скачиваний:
137
Добавлен:
02.05.2014
Размер:
9.68 Mб
Скачать

Chapter 15: Visual Basic Code Generation and Reverse Engineering

'##ModelId=39615A930379 Implements Parent

'##ModelId=39615AA50180

Private mParentObject As New Parent

'##ModelId=39615AA501C6

Private Sub Parent_PublicOperation() Call mParentObject.PublicOperation

End Sub

Reverse Engineering

As with code generation, reverse engineering with Visual Basic is done through a wizard. Rose Visual Basic includes a Model Update Wizard that will walk you through the steps of selecting the class(es) to reverse engineer and pulling them into your Rose model.

To begin the process, select Tools → Visual Basic → Update Model from Code. The reverse−engineering wizard will begin, as shown in Figure 15.11.

Figure 15.11: Visual Basic reverse−engineering wizard

If you have already created some Visual Basic components, Rose will list them and give you the option to select the components to reverse engineer. If not, Rose will prompt you to create a component, as shown in Figure 15.12.

537

Chapter 15: Visual Basic Code Generation and Reverse Engineering

Figure 15.12: Creating a Visual Basic component

To create a component, select Add a Visual Basic Component, or press Ctrl+A. Then select the type of component to create (Standard EXE, ActiveX EXE, ActiveX DLL, or ActiveX Control) and press Add.

When you are returned to the Select Components and Classes window, right−click the new component and select Properties. In the Project File field, enter the Visual Basic project to reverse engineer:

Once you have added a component (or if you already had components added), Rose will prompt you to select the components to reverse engineer. Press Next to see a summary screen, and then press Finish to start the reverse−engineering process.

If you did not start the project by using the Visual Basic framework, Rose will first reverse engineer a COM package with subpackages containing the standard Visual Basic classes and types:

538

Chapter 15: Visual Basic Code Generation and Reverse Engineering

Rose will then, of course, reverse engineer the classes you selected using the wizard. In the following example, we reverse engineered some of the classes in our airline example.

Each Visual Basic class is reverse engineered as a Rose class with the appropriate stereotype. Table 15.7 lists the Visual Basic class types and their corresponding Rose model stereotypes.

Table 15.7: Visual Basic−to−Rose Mapping

Visual Basic Class

Rose Stereotype

Class Module

Class Module

Interface

Class Module with Public visibility

Form

Form

MDI Form

MDI Form

DHTML Page

DHTML Page

Property Page

Property Page

Interface

Class Module with Public visibility

Module

Module

User Connection

User Connection

User Control

User Control

User Document

User Document

Web Class

Web Class

Template Web Item

Template Web Item

Custom Web Item

Custom Web Item

Data Environment

Data Environment

Data Report

Data Report

Add−In Designer

Add−In Designer

Collection

Class Module

Summary

In this chapter, we took a look at how various Rose model elements are implemented in Visual Basic. Using the code−generation properties for classes, packages, attributes, operations, associations, aggregations, and

539

Chapter 15: Visual Basic Code Generation and Reverse Engineering

other model elements, you have a great deal of control over what gets generated. Through the code−generation and reverse−engineering capabilities of Rose, you can keep your source code and Rose model synchronized.

Again, the steps needed to generate code are as follows:

1.

Create components.

2.

Assign classes to components.

3.

Set the code−generation properties.

4.

Select a class or component to generate on a Class or Component diagram.

5.

Select Tools → Visual Basic → Update Code to start the Code Generation Wizard.

6.

Select Tools → Visual Basic → Browse Source Code to view the generated code.

To reverse engineer a Visual Basic project, follow these steps:

1.

Create a component and assign a Visual Basic project to the component.

2.

Select Tools → Visual Basic → Update Model from Code.

3.

Select the component(s) and class(es) to update.

4.

Select Finish to complete the process.

In the next chapter, we will explore one of the newest features of Rational Rose: the XML DTD add−in. This new feature gives you the capability of modeling not only your application, but also the structure of your XML DTD files. You can use Rose to reverse engineer and visualize existing DTD structures or to model and generate new ones. As we will see in the next few chapters, Rose now has the ability to model your entire application: object model, XML DTD structure, database structure, and web components.

540