|I l @ ve RuBoard|
Step 1: Create Needed Property Sets
There are code-generation properties associated with the project, the class, roles, attributes, and operations. The properties applying to the project as a whole involve file name , default container names , and placement of the generated code. Class properties involve the generation of constructors, destructors, copy constructors, equality operators, and get/set methods. The property set for roles deals with the construction of get/set methods, visibility of the methods , and the container class to be used. Operation properties deal with the operation kind (common, virtual, abstract, static, or friend) and allow the operation to be made constant. These property sets may be edited, and new sets may be created to specify the C++ features needed for the project. Two files are generated for each classa header (.h) file and a specification (.cpp) file.
For a typical project, a few people are responsible for the creation of code generation property sets that are used by the entire development team. This enables each developer to generate the needed code for the components . Some typical property sets are Virtual destructor, Virtual operation, Abstract operation, Static operation, No get member function, and Forward reference.
CREATING PROPERTY SETS IN RATIONAL ROSE
The property set Virtual Destructor is shown in Figure A-1.
Figure A-1. Virtual Destructor Property Set
Step 2: Create Body Components in the Component Diagram
Rational Rose generates code based on the components and their stereotypes present in the diagram. For components without a stereotype, Rose will generate a .h file containing definition and declaration information for the class. For components with a stereotype of Package Specification, Rose will generate a .h file containing the definition information for the class. If there is a corresponding component with a stereotype of Package Body, Rose will generate a .cpp file containing declaration information for the class.
ASSIGNING STEREOTYPES TO COMPONENTS IN RATIONAL ROSE
The Component Specification is shown in Figure A-2.
CREATING COMPONENT HEADERS AND BODIES IN RATIONAL ROSE
Figure A-2. Component Specification
A component diagram with components for C++ .h and .cpp files is shown in Figure A-3.
Figure A-3. Updated Component Diagram
Step 3: Assign the C++ Language to the Components
Once the components for the header and body are created, they must be assigned the C++ language. If the default language for a model is set to C++ (Tools:Options menu, notation tab), Rational Rose automatically will assign the C++ to components in the model.
ASSIGNING A LANGUAGE TO A COMPONENT IN RATIONAL ROSE
The Component Specification for the Course class is shown in Figure A-4.
Figure A-4. Assigning a Language to a Component
Step 4: Assign Classes to Components
Once components have been created, classes are assigned to the components representing the header file.
ASSIGNING CLASSES TO COMPONENTS IN RATIONAL ROSE
Step 5: Attach Property Sets to Modeling Elements
Each modeling element (e.g., class, attribute, or role) is examined to determine its code needs. If a property set other than the default set is needed, it is attached to the modeling element.
ATTACHING A PROPERTY SET TO A SELECTED ELEMENT IN RATIONAL ROSE
The property set VirtualDestructor has been attached to the RegistrationUser class as shown in Figure A-5.
Figure A-5. Property Set Attachment
Since there are not property sets for every combination of elements, any property may also be overridden for a particular element. This is true even if the property is part of the default property set for the element.
OVERRIDING A PROPERTY IN RATIONAL ROSE
Step 6: Select the Components and Generate the Code
Code may be generated for an entire package, a component, or a set of components. The name of the component is used to generate the name of the file containing the code. The code is placed in a directory structure that corresponds to the package names in the component view.
GENERATING CODE IN RATIONAL ROSE
The Code Generation Status window is shown in Figure A-6.
Figure A-6. Code Generation Status
Step 7: Evaluate the Code Generation Errors
Rose writes all warnings and errors to the Log window. If a part of the design for the class is not complete, Rose will write a warning message to the log and use a default value. This is especially important if an iterative approach to development is being followed since an entire class may not be implemented in one iteration.
The common warnings and errors output from the code generator are
The Log window is shown in Figure A-7.
Figure A-7. Rational Rose Log Window
|I l @ ve RuBoard|