• No results found

Model Management

5.2 Model Difference

5.2.4 Related Operations

Model difference is probably the main operation for dealing with model evolution and for handling model versions, but it is not the only one required to achieve such processes. There are other related operations that need to be considered too, such as those that do and undo the changes, compose several differences, etc. For instance, operationsdoandundowill allow us to obtain the minuend model from the subtrahend model, and vice versa, respectively.

In fact, one of the current limitations of other proposals that implement model comparison and difference (e.g., [91]) is that their results cannot be effectively composed, and that these additional operations are hard to define. In our approach, given the way in which the differences have been represented (as models) and the modelDiff operation has been specified (as an operation on models), they become natural and easy to define [109].

5.2.4.1 The do Operation

Given a model Ms conforming to an arbitrary metamodel MM and a difference model Md

(conforming to the Difference Metamodel), the result of applying operation do to them is another modelMmso that: do(Ms,Md) = MmandmodelDiff(Mm,Ms) = Md.

Operationdoapplies to a model all the changes specified in a difference model. Basically, it adds to the model all elements referred to byAddedElementsof the difference model; deletes from the model all elements referred to byDeletedElements of the difference model; and modifies those elements of the model which are referred to byModifiedElements.

In Maude, this operation can be specified by three equations (described below) that corre-spond, respectively, to the addition, deletion and modification of elements. A fourth equation

is also included to deal with the empty difference:

1 v a r s MM1 MM2 : @Metamodel .

2 v a r s OBJSET1 OBJSET2 : Set{@Object} .

3 v a r s O1 O2 OLDO NEWO : Oid .

4 v a r s C1 NEWC OLDC : @Class .

5 v a r s SFS1 OLDSFS NEWSFS : Set{@StructuralFeatureInstance} .

6

7 op do : @Model @Model ˜> @Model .

8 eq do( MM1 { OBJSET1 } , MM2 { OBJSET2 }) = otherMM ( MM1 , OBJSET2 ) { do ( OBJSET1 , OBJSET2 ) } .

9

10 op do : Set{@Object} Set{@Object} ˜> Set{@Object} .

11 eq do( OBJSET1 , < O2 : AddedElement | element : NEWO >

12 < NEWO : NEWC | NEWSFS > OBJSET2 )

Operation otherMMgets the metamodel of the minuend model by looking for it through the classes of the difference model (note that model difference can be applied over models con-forming to different metamodels). The auxiliary operationoriginalIdrecovers the original identifier of the object that was modified, i.e., reverts the changes done by operationsnewId or oldId in the model difference. Operation excludingAll deletes from a set of struc-tural feature instancesSFS1all the structural feature instances that have the same name of any structural feature instance of theOLDSFSset. This operation is used in line 23 to remove from SFS1the structural features that have the old values (OLDSFS), to add them again but with the corresponding new values (contained inNEWSFS).

Note that a matching between both models (Ms and Md) is not needed, because opera-tiondo is supposed to be applied to the original model of the difference, and original object identifiers can be recovered from the difference model.

The resulting model Mm will usually conform to the same metamodelMM of Ms. How-ever, model difference can be applied to models conforming to different metamodels. In gen-eral, model difference will be applied to models conforming to the same metamodel, or

meta-models that are related by the sybtyping relationship. Therefore, we could usually affirm that the resulting modelMm will conform to a metamodel which is a subtype [120] (or, in special cases, supertype) of the metamodelMM of the original subtrahend Mm.

5.2.4.2 The undo Operation

Given a modelMm conforming to a metamodelMM and a difference model Md(conforming to the Difference Metamodel), the result of applying operationundoto them is another model Mmso that:undo(Mm,Md) = MsandmodelDiff(Mm,Ms) = Md. As well as in operation do, the resulting modelMswill usually conform to the same metamodel MM of Mm (if this was true when the difference was done).

This operation reverts all the changes specified in a difference model. Operation undo can be considered as the inverse operation ofdo. Basically, it adds to the model all elements referred to byDeletedElementsof the difference model; deletes from the model all elements referred to byAddedElements of the difference model; and modifies those elements of the model that are referred to byModifiedElements(but in the opposite way of operationdo).

Since the equations for theundooperation are analogous to the equations for thedooperation, we will not include them here.

5.2.4.3 Sequential Composition of Differences

Another important operation provides the sequential composition of differences. In general, each difference model represents the changes in a model from one version to the next, i.e., a delta (∆). The diffComposition operation specifies the composition of deltas, so that individual deltas can be combined into a single one.

This operation is very useful, for instance, to “optimize” the process of applying succes-sive modifications to the same model, which might introduce complementary changes. For example, if one element is added in one delta and then deleted in another, the composed delta does not need to store both changes. In this way, this operation not only composes deltas, but also eliminates unnecessary changes and provides more compact model differences, hence improving efficiency.

The following Maude equations are a fragment of thediffCompositionoperation spec-ification. The first equation corresponds to the composition of an addition and a deletion of the same element. In this case, as mentioned before, there will be no evidence of the element in the resulting difference model. The second equation corresponds to the composition of an

addition and a modification of the same element. In this case, anAddedElementthat refers to the element with its attributes properly modified, and the element itself, will be included in the resulting difference model.

op diffComposition : @Model @Model ˜> @Model .

eq diffComposition( @Difference@ { OBJSET1 } , @Difference@ { OBJSET2 })

= @Difference@ { diffComposition ( OBJSET1 , OBJSET2 ) } .

op diffComposition : Set{@Object} Set{@Object} −> Set{@Object} . ce q diffComposition(< O1 : AddedElement | element : NEWO >

< NEWO : NEWC | NEWSFS > OBJSET1 ,

< O2 : DeletedElement | element@DiffElement : OLDO >

< OLDO : OLDC | OLDSFS > OBJSET2 )

= diffComposition ( OBJSET1 , OBJSET2 ) i f originalId( OLDO ) = originalId ( NEWO ) .

ce q diffComposition(< O1 : AddedElement | element : O >

< O : C | SFS > OBJSET1 ,

< O2 : ModifiedElement | element : NEWO # oldElement : OLDO ) >

< OLDO : OLDC | OLDSFS >

eq diffComposition( OBJSET1 , OBJSET2 ) = OBJSET1 OBJSET2 [ owise ] .

When no correspondences are found between the two difference models, i.e., when the dif-ference models do not contain more DiffElementsthat refer to the same element, all their remaining elements (DiffElements) are just included in the composition (as specified by the last equation).