Synchronization Between Models and Source Code
Go Up to Modeling Concepts
- 1 Types of synchronizations
- 2 Synchronization among Modeling Views
- 3 Synchronization between source code and UML models
- 4 Class diagrams
- 5 Synchronizing properties implemented as documentation comments
- 6 Explicit synchronization commands
- 7 See Also
Types of synchronizations
The Modeling provides different types of synchronizations in different types of modeling projects:
- Design Projects
- In a design project, the Modeling provides synchronization between the model tree in the Model View and all kinds of diagrams in the Diagram View.
- Implementation Projects
- In an implementation project, the Modeling provides the permanent synchronization among different representations of your implementation modeling project:
- Model View -- Hierarchy tree of all items in the modeling project.
- Diagram View -- Modeling diagrams. Class diagrams are synchronized with the source code.
- Source code -- Delphi source code of classes, interfaces, and other programming structures in implementation projects.
- For diagrams of other types than class diagrams, the Modeling provides only the synchronization between the model tree in the Model View and all kinds of diagrams in the Diagram View (as for design projects).
Synchronization among Modeling Views
The Modeling uses several of the IDE's view features to manage models. The main views are the Model View, Diagram View, and Object Inspector. The Modeling uses these views in close cooperation. When you implement changes of model elements in one of these views, the Modeling immediately synchronizes other views to reflect these changes:
- Model View
- The Model View shows you the logical structure of your projects in a tree, as opposed to the file-centric view of the Project Manager. Each project in a project group is a top-level node on the model tree shown in the Model View. Nested within each project tree-node, you will find nodes of UML packages. You can expand a UML package to reveal the types (classes, interfaces, and so on) and diagrams declared in it.
- Diagram View
- The Modeling uses the Diagram View to show diagrams (including class diagrams) defined in a model. In the Model View, double-click a diagram node -- the diagram opens in the Diagram View.
- Object Inspector
- The Modeling uses the Object Inspector to show the properties of a model element that you select in the Model View or Diagram View.
Synchronization between source code and UML models
The real time synchronization in an implementation project between the UML model and the Delphi source code of this project is the key feature of the Modeling.
The Modeling's source code synchronization refers to:
- Source Code Visualization
- The ability to scan your Delphi source code and map declarations within that code onto UML notations and then to represent this mapping in graphical view.
- Source Code Generation
- The opposite ability to generate the Delphi source code representing your graphical model.
The Modeling maps certain source code constructs (such as class declarations and implementations of interfaces) onto their UML counterparts, which are then displayed on class diagrams in the Diagram View and on the modeling project tree in the Model View. Thus source code synchronization presents a graphical view (the model tree and class diagrams) of your source code and these model tree and class diagrams reflect directly the source code.
The source code synchronization refers to the following Modeling features:
- When you turn ON the Modeling Support to a Delphi project, the Modeling parses the existing source code of the Delphi project and converts it to the implementation project by generating proper modeling entities. The generated modeling entities include the model tree to be managed in the Model View and class diagrams to be managed in the Diagram View.
- When you make changes in your Delphi source code in the Code Editor, the Modeling immediately automatically updates the proper class diagrams in the Diagram View and the proper elements of the model tree in the Model View. The resulting diagram and model tree are "live", in the sense that they always reflect the current state of the source code.
- ATTENTION ! Notice that some direct changes of Delphi source code in the Code Editor, such as renaming a class, cannot be correctly tracked by the Modeling. Use Refactoring operations for this purpose.
- The Modeling also provides the ability to design your application on the diagramming surface.
- The Modeling immediately maps changes implemented in the model tree or class diagrams into the existing Delphi source code:
- When you create a new or change an existing class diagram, the Modeling immediately updates the corresponding Delphi source code to synchronize it with the class diagram.
- You can make changes directly in the class diagram in the Diagram View or in the model tree in the Model View and the Modeling immediately reflects these changes in your Delphi source code.
- Changing a name, adding a member, creating a new link, or applying a pattern on the diagramming surface makes the corresponding changes in the actual source code.
Class diagrams are the kind of UML static structure diagrams. A structural view of your project focuses on UML packages, data types such as classes and interfaces, and their attributes, properties, and operations. Class diagrams also graphically show the relationships that exist between these entities. That is, class diagrams show the logical relationships (or static structure in UML terms) of classes, interfaces, packages, and other entities defined in your modeling project.
The Modeling immediately synchronizes any changes among elements of class diagrams, corresponding elements of the model tree, and the corresponding Delphi source code.
Inheritance and interface implementation
Generalization is the UML term for the relationship when one class inherits from a superclass. When the Modeling sees an inheritance relationship in your source code, it creates a generalization link within the child class node in the Model View tree. On the class diagram in the Diagram View, the generalization link is shown using the standard UML notation of a solid line with a hollow arrowhead pointing at the superclass and starting from the child class.
Interface Implementation is the UML term for an interface implementation by a class. Similar to the case of inheritance, the Modeling creates an implementation link when it sees a class declaration that implements an interface. In the Model View tree, the implementation link appears within the node of the class implementing the interface. On the class diagram, the implementation link appears as a dotted line with a hollow arrowhead pointing at the interface and starting from the class. There will be one such implementation link for every interface implemented by the class.
In UML, an association is a navigational link produced when one class holds a reference to another class (for example, as an attribute or property). The Modeling creates an association link on a class diagram when one class contains an attribute or property that is a non-primitive data type. On a class diagram, an association link is represented as a solid line between the class containing the non-primitive member and the data type (class) of that member.
Class members: attributes, methods, properties, and nested types
The Modeling can also map declarations of class and interface members to their UML equivalents. Within the elements on class diagrams in the Diagram View, members are grouped into distinct compartments:
- Fields -- Contains declarations of fields. The type and optional default value assignment are shown on a diagram.
- Methods -- Contains declarations of methods. Visibility, scope, and return value are shown.
- Properties -- Contains declarations of Delphi properties. Types of properties are shown.
- Classes -- Contains declarations of nested classes.
- They can be used in other compartments, like Interfaces. Available types of these compartments depend on the type of the modeling project (design projects, Delphi implementation projects).
Standard UML syntax is used to display UML declarations of attributes, methods, and properties. Each of the four categories can be independently expanded or collapsed to show or hide the members within.
Synchronizing properties implemented as documentation comments
Some properties that are defined for the model elements and members in the Object Inspector are presented in the source code as language-specific documentation comments. In particular, these properties are: Author, Since, Version, Stereotype, Associates, and so on.
For example, if you define that the property Author has the value
Embarcadero, then the Modeling will generate in your Delphi source code the following documentation comment:
When the Modeling encounters such comments in the source code, it reverse engineers them to the appropriate properties of the model elements.
Explicit synchronization commands
You can use the following commands to explicitly enforce synchronization:
- Model View -- You can use:
- The Reload command to explicitly refresh the UML model (to reload the entire model) from the source code. It is available on the root project node for implementation projects.
- The Refresh Model View toolbar button to refresh the model tree.
- Diagram View -- You can use the Update command (or press F5) to update the diagram.