Relationships between UML model elements and UML-to-C++ transformation output

Traceability options enable you to create relationships between a source model and the transformation output.

The options in the transformation configuration enable to you specify the type of relationship that the transformation generates between a model element and the transformation output. By default, the transformation does not create traceable relationships.

Derived relationships between source model elements and transformation output

To understand how the elements of your source model relate to the elements in your target project, you can have the transformation create derived relationships from the source model elements to the generated elements in the target project. You can then view the derived relationships in a topic diagram by creating and running model queries. When the system visualizes the generated code element, the derived relationship between the source element and the code element is visible.

When you run a transformation that is configured to generate derived relationships between the source model and transformation output, for each UML element that is part of the transformation source, the transformation adds a source code comment to the transformation output. The comment begins with //@uml.annotations and contains a unique identifier for the model element.

To view the relationships between source model elements and transformation output, you can visualize the source model element in a diagram and drag the code element that the transformation generates into that diagram. The following table lists the UML representation for a source model element named Class1, the code that the transformation generates, and the class diagram that shows the derived relationship between the elements.
UML element Transformation output Derived relationship in class diagram
This image shows a UML class named Class1 that has an integer attribute named  attribute1. Class1 also contains two operations, named Operation1 and Operation2. These operations do not have any  input or output parameters.
#ifndef CLASS1_H
#define CLASS1_H
//Begin section for file Class1.h
//TODO: Add definitions that you want preserved
//End section for file Class1.h

//@uml.annotationsderived_abstraction="platform:/resource/MyModels/UMLModel.emx#_biwQUHdCEduVaMk1fL7Qcw"
//@generated "UML to C++ (com.ibm.xtools.transform.uml2.cpp.CPPTransformation)"
class Class1 {

    //Begin section for Class1
    //TODO: Add attributes that you want preserved
    //End section for Class1

    private:

        //@generated "UML to C++ (com.ibm.xtools.transform.uml2.cpp.CPPTransformation)"
        int attribute1;
    public:

        //@generated "UML to C++ (com.ibm.xtools.transform.uml2.cpp.CPPTransformation)"
        int Operation1();

        //@generated "UML to C++ (com.ibm.xtools.transform.uml2.cpp.CPPTransformation)"
        int Operation2();

};  //end Class Class1

#endif
This image shows a class diagram with an abstraction relationship between UML Class1 and the visual representation for Class1. The derive stereotype is applied to the relationship.

The transformation does not alter the source model when you specify that the transformation generate derived relationships.

Creating derived relationships is useful in large projects that might contain multiple models and multiple transformation configurations. You can also create and run traceability queries that display how transformation output relates to software specifications and model elements.

Direct references between model elements and transformation output

You can instruct a transformation to create direct references between source model elements and transformation output. The transformation replaces source model elements with pointers to the transformation output. The source code that the transformation generates becomes the primary engineering artifact, and the elements in the model become visual representations of the code. This practice is useful if you want to work in the target domain instead of working with the UML model. The changes that you make to the visual representations of the objects in the model are immediately visible in the code.

Running a transformation that creates direct references between model elements and transformation output changes the source model. To avoid possible problems, you should place your source model under source control.

To realize the benefits of working in the target domain, you should create direct references when you make incremental changes to a UML model, and then convert the model into visual representations of code. If the transformation cannot transform UML elements, such as nested elements, it moves these elements to the nearest package. If the transformation cannot move a model element to the nearest package, it deletes the element.

To learn about creating direct references between model elements and transformation output, see the related tutorial for this topic. Although the tutorial demonstrates this concept using the UML-to-Java transformation, you can perform the same procedure using the UML-to-C++ transformation.

Related tasks
Preventing UML-to-C++ transformations from creating relationships between UML model elements and transformation output
Creating derived relationships between UML source model elements and UML-to-C++ transformation output
Replacing source model elements with shortcuts to UML-to-C++ transformation output
Creating relationships between UML model elements and UML-to-C++ transformation output
Related reference
Interpretation of UML model elements by UML-to-C++ transformations
Related information
Tutorials for transformations

Feedback