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

Chapter 15: Visual Basic Code Generation and Reverse Engineering

Setting Visual Basic code−generation properties

Generating Visual Basic code from your Rose model

Mapping Rose elements to Visual Basic constructs

Reverse engineering Visual Basic code into a Rose model

Starting a Visual Basic Project

Rather than start from scratch, you may want to import the standard Visual Basic classes into your Rose model. By doing so, you will have access to all of the standard classes and interfaces, and you can set up the appropriate relationships between your classes and the standard Visual Basic classes. This, in turn, will help in the code−generation and reverse−engineering processes.

Begin by creating a new Rose model. When the Framework Wizard appears, select Visual Basic Standard. The Visual Basic framework will be loaded, and the classes will show under the stdole Ver 2.0, VB Ver 6.0, VBA Ver 6.0, and VBRUN Ver 6.0 packages in the Logical view. Your Rose model will look like Figure 15.1.

Figure 15.1: Visual Basic framework

Each of these four packages contains a set of standard classes, interfaces, and relationships. Each package contains an overview diagram that presents the elements in the package and the relationships between them. You can familiarize yourself with the model elements in the packages and then set up the needed relationships between your classes and the standard ones.

Visual Basic Code−Generation Properties

Visual Basic code generation using Rational Rose is extremely flexible. You have full control over what gets generated and many of the details of how the generated code will look. For example, for each class, you can

494

Chapter 15: Visual Basic Code Generation and Reverse Engineering

decide if initialization and termination routines will automatically be created. For each attribute, you control the visibility, name, and whether Get and Set operations should automatically be created. For each module, you control the filename. For each generalization, you control if the implements delegation is used.

All of these things are controlled through the code−generation properties. Rose provides property sets that deal with classes, attributes, operations, module specifications, associations, and generalizations.

You can see all of these properties by selecting Tools → Options, then selecting the Visual Basic tab.

Anything you change using this window will set the default for all classes, attributes, operations, and so on.

You can also set the code−generation properties for a single class, attribute, operation, or other model element. To do so, open the specification window for the model element and select the Visual Basic tab. On this tab, you can change the properties that apply to that particular type of model element.

Finally, you can set the properties using the Visual Basic Model Assistant. The Model Assistant is a visual tool used to provide detailed information for a class or other model element. These details are then used in the code−generation and reverse−engineering processes.

In the following sections, we'll examine the code−generation properties for classes, operations, attributes, and modules. We'll look at how to set the properties using the specification window or the Model Assistant.

Class Properties

Class properties are the Visual Basic code−generation properties that apply to classes. These properties will let you change the class name and set other class−specific properties.

495

Chapter 15: Visual Basic Code Generation and Reverse Engineering

There are three places to set these properties. To set them for all classes, select Tools → Options, then click the Visual Basic tab and select Class from the drop−down list box. To set them for only one class, select the Visual Basic tab on the class specification window and edit the properties there, or use the Model Assistant.

Table 15.1 lists the Visual Basic class properties, their purposes, and their default values.

Table 15.1: Class Code−Generation Properties

Property

Purpose

Default

Update Code

Specifies if code can be updated for the class

True

Update Model

Specifies if the model can be updated for the class

True

OptionBase

Sets the base identifier for arrays (usually 0 or 1)

<blank>

OptionExplicit

Controls whether variable names must be explicitly declared

True

OptionCompare

Controls the method by which string comparisons are made

<blank>

Instancing

Determines how classes are exposed to other applications

MultiUse

Many of these class properties can be set using the Model Assistant. To open the Model Assistant, right−click the class and select Model Assistant. The window shown in Figure 15.2 will be displayed.

496

Chapter 15: Visual Basic Code Generation and Reverse Engineering

Figure 15.2: Using the Model Assistant's Class tab to set class properties

The Should Be Generated field corresponds to the Update Code property and determines whether the class will be reflected in the generated code. The Should Be Updated from Code field corresponds to the Update Model property, and the Instancing field corresponds to the Instancing property.

In addition to these fields, you can set the following information using this screen:

The Abstract Interface field sets the class as abstract. No method bodies will be created for this class.

The Stereotype field sets the type of class (class module, interface, form, collection, module, etc.). Select one of the standard Visual Basic stereotypes from the drop−down list box. The stereotype you select controls what type of class Rose will generate in Visual Basic.

The Collection Class field is used to create a new, user−defined collection class. Rose will create the collection class and set up a dependency between the collection class and the current class:

497