Two people begin a modeling project, and their first instinct is to model the system independently. At some point, they feel that they have sufficiently proven the concept, and they want to start the project proper. Best practice would indicate that their ad-hoc models should now be combined into a single model that can be taken forward into version control. This is a very common scenario in modeling projects.
The primary goal is to arrive at a common set of semantic elements that are shared by all diagrams within the model. However, since each modeler has diagrams that point to the local set of semantic elements, it is necessary to retarget all diagram references to the new common set of elements.
In IBM® Rational® Software Architect Version 6.x, the procedure for this is complex. You need to drag each unique semantic element into the target model (into a shared package for example), and then drag all the useful attributes from duplicate semantic elements in the source model to the equivalent element in the target model. Once you have done this for all semantic elements, you drag the diagrams in the source model into an appropriate location in the target model, and the source model is deleted.
This breaks all references in the diagrams that are still referencing the semantic elements from the source model. Model validation is run at this point, and all references to semantic elements are reconnected to the new common elements using Quick Fix.
This is a tedious and error-prone method, but it is at least possible to do it.
A better solution
In Rational Software Architect Version 18.104.22.168 and later, there is a much better solution to this problem with the new Combine Models command. The source and target models appear in a dialog, where elements are aligned, unique elements are marked for inclusion in the final set of semantic elements, and names are adjusted as necessary.
Diagrams are also marked for inclusion in the target model, and the fuse facility takes care of retargeting all references to the new common semantic elements.
This is now a quick and painless procedure.
A simple example
The following example is greatly simplified, but illustrates just how easy it is to fuse independently created models without losing any diagrams or elements.
Assume two models that are similar in structure and content. The goal is to create a single model with all the unique elements from each and with all diagrams preserved and retargeted to the new shared semantic elements.
Note: the following procedure requires Rational Software Architect Version 22.214.171.124 and later, as previous versions of Rational Software Architect 7 were excessively protective of model integrity and were unable to retarget any but the most trivial set of changes.
Figures 1 through 4 show details about the two models.
Figure 1. Semantic Elements and Structure of Model 1
Figure 2. Diagram of Model 1
Figure 3. Semantic Elements and Structure of Model 2
Figure 4. Diagram of Model 2
Combine the two models
These two models have nearly identical structure, but the names and identities of all the elements are quite different. There are diagrams in each model that need to be preserved in the final (target) model.
Looking at the two models, you decide that class
class1 will align with class
class2 will align with class
B, and interface
interface1 will align with interface
The Combine Models command is available on the pop-up menu when two models with different identities are selected, as shown in Figure 5.
Figure 5. Combine Models command
Select the target model
This command starts the Combine Models target selection dialog shown in Figure 6.
Figure 6. Choosing the source and target models
This dialog selects the source and target models for the fusion. Typically, in ad-hoc modeling scenarios, the target model will be preserved and the source model will be deleted after all the useful elements and diagrams have been copied or combined.
You should only select the Attempt to combine models automatically checkbox if there are only additions in the two models, and there is no alignment required. In this article’s scenario, alignment and combination of like elements is the point of the technique, so the box is not selected.
Fuse dialog: align the models
The fuse dialog has two main panes: the source and the target model trees, as shown in Figure 7. Trees are displayed because this operation is all about model structure. Identities are irrelevant when merging by structure.
Figure 7. Visual Combine
When you select the checkboxes on the left, those elements will be included in the target model. You should examine and select each element individually in order to bring it across to the target. The first step, however, is to align the common elements.
Align an element using manual mapping
Right-click the element to choose it as the source element of a manual mapping, as shown in Figure 8.
Figure 8. Select Source element
The target element has a similar option, as shown in Figure 9.
Figure 9. Select Target element
Confirmation is requested in the Create Manual Mapping dialog shown in Figure 10.
Figure 10. Confirming the Manual Mapping
After you create a manual mapping entry, it displays in the manual mappings pane as shown in Figure 11.
Figure 11. Displaying the manual mapping
Align the rest of the elements as described earlier. As a useful byproduct of aligning the classes and the interface, Rational Software Architect automatically aligns the relationships, as shown in Figure 12.
Figure 12. Relationships are automatically aligned
Select the Source Diagram for inclusion in the target
Why is there no checkbox in Figure 13 allowing you to copy the source diagram into the target?
Figure 13. Source diagram with no option to select it
This happens because diagram deltas have been filtered out by default. To remove the filter, clear it in the list of filters by selecting Filter out Diagram Changes, as shown in Figure 14.
Figure 14. Clear Filter out Diagram Changes from the filter list
Now, the checkbox is available and you can select it, as shown in Figure 15
Figure 15. Select the Source diagram
The diagram is shown unaligned with the other diagram of the same name. This is the desired result, as both diagrams will be available in the target when the fuse is completed. Since there is no structural content inside a diagram, they are intentionally left unaligned.
There are numerous filters available to remove differences of various types. This is useful so that a session may be tuned to a particular purpose. However, when performing an ad-hoc modeling session, all filtering is best left off so no differences are suppressed.
Choose the final names
For illustrative purposes, Figure 16 show’s class2’s name chosen instead of the equivalent class name (B) in the target model.
Figure 16. Choosing the name
You can override an element’s name with one that appears in neither model. To do so, right-click the element and select Override Name, as shown in Figure 17.
Figure 17. Override the name
Now enter a new name (in this case
MySpecialInterface), as shown in Figure 18. The new name displays in the source tree shown in Figure 19.
Figure 18. Entering a new name
Figure 19. The new name displays
All you had to do to combine these two models, with all useful element data and diagrams preserved, was the following:
- Perform a bit of alignment using manual match
- Check the diagram after removing the filter
- Choose a couple of names
Clicking OK on the fuse dialog combines the two models into one. In less than a second, the system asks you if you want to reload the target model. Of course, the answer is Yes, as shown in Figure 20.
Figure 20. Reload the target model
New Target Model semantic elements and structure
Note (in Figure 21) that all of the changes were made successfully.
Figure 21. The final results of combining the models
Note that there are two class diagrams, and all of the relationships appear to have been correctly realigned to the new target elements.
The two class diagrams are similarly correct, as shown in Figure 22.
Figure 22. The class diagram details
The layout of the second diagram has been affected by the overridden name’s new size. Running automated layout (right-click and select Arrange All, as shown in Figure 23) fixes this easily. Figure 24 shows the results.
Figure 23. Selecting Arrange All
Figure 24. The rearranged diagram
Rational Software Architect V126.96.36.199 and later makes combining independently-developed models a simple and very effective way of moving from the ad-hoc modeling stage of a project into the more formal version controlled stage.
The techniques presented in this article are also used when reconciling models to code using the Java to UML transform as the reverse of the UML to Java 5 transform. The temporary model that is constructed by the transform is used as the source in a fuse dialog, and the original UML model is used as the target.
The techniques as presented in this article are usable for this reconciliation operation, which provides a powerful mechanism for examining and capturing architectural and structural changes from the code base.
- Part 1 in this series, Comparing models with local history (developerWorks, July 2005).
- Part 2 in this series, Merging models using "compare with each other" (developerWorks, July 2005).
- Part 3 in this series, A deeper understanding of model merging (developerWorks, July 2005).
- Part 4 in this series, Parallel model development with CVS (developerWorks, August 2005).
- Part 5 in this series, Model management with IBM Rational ClearCase and IBM Rational Software Architect Version 7 and later (developerWorks, July 2007).
- Part 6 in this series, Parallel model development with custom profiles (developerWorks, August 2005).
- Stay current with developerWorks technical events and Webcasts.
- IBM Rational Software Architect product page: Find technical documentation, how-to articles, education, downloads, and product information about Rational Software Architect.
- Visit IBM's Pattern Solutions and find out what IBM is doing around patterns and reusable assets.
- Browse the technology bookstore for books on these and other technical topics.
Get products and technologies
- Download a free trial version of Rational Software Architect.
- Download IBM product evaluation versions and get your hands on application development tools and middleware products from DB2®, Lotus®, Rational®, Tivoli®, and WebSphere®.
- Participate in developerWorks blogs and get involved in the developerWorks community.
- Rational Software Architect, Data Architect, Software Modeler, Application Developer and Web Developer forum: Ask questions about Rational Software Architect.
Dig deeper into Rational software on developerWorks
Get samples, articles, product docs, and community resources to help build, deploy, and manage your cloud apps.
Experiment with new directions in software development.
Software development in the cloud. Register today to create a project.
Evaluate IBM software and solutions, and transform challenges into opportunities.