Cleanup Before Construct

This is a bx pattern which has been identified in several bx examples.

Summary

The pattern defines a two-phase approach in both forward and reverse transformations associated with a bx with relation R: the forward transformation R-> first removes all elements from the target model n which fail to satisfy R for any element of the source m, and then modifies or constructs elements of n to satisfy R with respect to m. The reverse transformation R<- operates on m in the same manner.

Application Conditions

A transformation tau should operate on source m and target models n to establish a relation R between them, by modifying n. Changes to m need to be propagated to changes to n.

Solution

Apply a cleanup transformation tauX to: (i) remove elements of n that do not correspond to elements of m; (ii) modify where necessary elements of n that correspond to elements of m, to re-establish R between them. The original transformation tau is then applied incrementally to (iii) create new elements of n where necessary to establish R.

Benefits:

The pattern is an effective way to ensure the correctness of separate-models bx: all target elements which invalidate R are removed or modified to enforce R.

Disadvantages:

There may be efficiency problems because for each target model element, a search through the source model for possibly corresponding source element(s) may be needed. Elements may be deleted in the Cleanup phase only to be reconstructed in the Construct phase: use of Auxilliary Correspondence Model is a means to avoid this problem, by enforcing that feature values should change in response to a feature value change in a corresponding element, rather than deletion and recreation of elements.

Related Patterns:

This pattern is a variant of the Construction and Cleanup pattern. It can use Auxiliary Correspondence Model.

Examples:

An example is the Composers bx (bx repository). Implicit deletion in QVT operates in a similar manner, but can only modify models (domains) marked as enforced. In UML-RSDS, explicit cleanup rules CnX can be deduced from the construction rules Cn, for mapping transformations (UML-RSDS Manual).