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

Chapter 12: Introduction to Code Generation and Reverse Engineering Using Rational Rose

Use the Component icon on the Diagram toolbar to add a new component to the diagram. See Chapter 10 for more information about adding components.

Step Three: Map Classes to Components

Each source code component represents the source code file for one or more classes. In C++, for example, each class is mapped to two source code components, one representing the header file and one representing the body file. In PowerBuilder, many classes are mapped to a single component. A PowerBuilder source code component is a PowerBuilder library (.pbl) file. In Java, each source code component represents a single .java file. Components are also created for ActiveX controls, applets, DLL files, executable files, and other source and compiled files.

The third step in the code−generation process is to map each of your classes to the appropriate components. For PowerBuilder, you must map each class to a component before you can generate code. However, this is an optional step with C++, Java, or Visual Basic. If you are generating Java or Visual Basic code, Rose will also generate the appropriate components and map the classes for you. However, components will not be automatically created for C++. It's a good idea to go ahead and complete this step regardless of the language you are using.

To map a class to a component:

1.

Right−click the component on a Component diagram or in the browser.

2.

Select Open Specification from the shortcut menu.

3.

Select the Realizes tab.

4.

On the Realizes tab, right−click the appropriate class or classes and select Assign from the shortcut menu.

5.

The browser will show the component name in parentheses after the class name in the Logical view.

OR

1.

Locate the class in the Logical view of the browser.

2.

Drag the class to the appropriate component in the Component view.

3.

The component name will appear in parentheses after the class name in the Logical view.

405

Chapter 12: Introduction to Code Generation and Reverse Engineering Using Rational Rose

Step Four: Set the Code−Generation Properties

There are a number of code−generation options you can set for classes, attributes, components, and other model elements. These properties control how the code will be generated. Common default settings are provided in Rose.

For example, one of the code−generation properties for a C++ attribute is GenerateGetOperation, which controls whether or not a Get() operation will be created for the attribute. One of the properties for a Java class is GenerateDefaultConstructor, which controls whether or not a constructor should automatically be created for the class. One of the properties for a relationship in Visual Basic is GenerateDataMember, which controls whether or not an attribute will automatically be created to support the relationship.

Each language in Rose has a number of code−generation properties. In the following chapters, we'll discuss the code−generation properties for specific languages. Before you generate code, it's a good idea to examine the code−generation properties and make any needed changes.

To view the code−generation properties, select Tools → Options, then select the appropriate language tab. For example, here is the tab for the Visual Basic properties:

From the drop−down list box, you can select Class, Attribute, Operation, or the other types of model elements. Each language will have different model elements available in the drop−down list box. As you select different values, different property sets will appear. We just saw the Class properties in Visual Basic. Here are the Attribute properties.

406

Chapter 12: Introduction to Code Generation and Reverse Engineering Using Rational Rose

Any changes you make to a property set in the Tools → Options window will affect all model elements using that set. For example, if you change the GenerateDefaultConstructor Class property on the Java tab, this change will affect all classes in your model that will be implemented in Java.

At times, you may want to change the code−generation properties for a single class, attribute, operation, or other model element. To do so, open the standard specification window for the model element, and then select the appropriate language tab. Any changes you make in the specification window for a model element will affect only that model element.

407

Chapter 12: Introduction to Code Generation and Reverse Engineering Using Rational Rose

Cloning Property Sets

Rather than making changes directly to the default property sets, you can clone them and then make changes to the copy. To clone a property set, press the Clone button on the Clone the Property Set window. Rose will prompt you to enter a name for the new property set.

Once you've cloned a property set, it will be available by opening the Set drop−down list box on the Clone Property Set window.

You can make as many changes as you'd like to this cloned set, without affecting the original default set. We recommend leaving the default set alone and only changing cloned sets.

408