CONFIGURATION KNOWLEDGE REFACTORING
4.2 LAWS FOR REFACTORING CK
!""#$"
! !"#$$%
& %$'()*&
! %$'()*!
% !,--,.
/(#*01(+23'1($$4,. %$$(*$
% !"#$$%&'
!())(*
+ %$,-./+
! %$,-./!
!
Figure 4.3 Refactoring example: Merge items with equivalent expressions.
4.2 LAWS FOR REFACTORING CK
The previous section illustrates cases of specific CK refactorings. For example, consider the transformation in Figure4.3, where we merge rows that have propositionally equiva-lent feature expressions (A). Instead of focusing on the details of a specific situation like that, we can generalize this refactoring. This section presents a set of laws, which are operations on a given CK, that preserve its semantics. These laws might be used as basis for the derivation of elaborate CK refactorings.
Law 1: Simplify Feature Expression using propositional reasoning
For example, we can replace a feature expression exp with another exp’ if they are propositionally equivalent. For instance, replacingA∨A with A. Figure 4.4 establishes this law.
!""#$"
!!! !!!
"#$ %&
'"%()*"+,#$*"--./0
1--"(-!!! !!!
"#$2 %&
!
!"#$!$!"#%
Figure 4.4 Simplify Feature Expression using propositional reasoning template.
A law consists of two templates (patterns) of equivalent CK models, on the LHS and RHS. We apply a law whenever the template is matched by a CK. A matching is an assignment of all variables occurring in LHS/RHS models to concrete values. A law may declare meta-variables. For instance, in the example above, we useexpto denote a feature
4.2 LAWS FOR REFACTORING CK 55 expression and a1 to denote an asset. A variable remains constant if it appears on both models. A condition might be specified below the template. Since each law defines two semantics-preserving CK transformations, the condition holds for both directions of the transformations. The dots used in the templates represent other CK items that remain unaltered. The application of the presented laws in a certain direction is not necessarily always a refactoring. As we see on some of the subsequent laws, there are occasions where it might be better to apply a law from left to right, whereas in other situation, it is better to apply it from right to left.
Law 2: Simplify Feature Expression using the FM
Likewise Law 1, a feature expression might be equivalent to another, but according to the FM. This law is established on Figure 4.5. We replace exp with exp’ (or vice versa) whenever evaluation ofexp is equivalent to evaluation ofexp’ for all product configura-tions from the FM. Notice that this is slightly different than the previous law, where we do not use the FM to compare the expressions — it is a special case of this law. The previous law can be derived from this law, but not the contrary. The condition states that if, according to fm, exp is equivalent to exp’, application of this law in both directions preserves the CK semantics.
'"%()*"+,#$*"--./0
1--"(-!!! !!!
"#$ %&
!
!"!!!!"#$%!!!#$%&'
'"%()*"+,#$*"--./0
1--"(-!!! !!!
"#$2 %&
!"
Figure 4.5 Simplify Feature Expression using the FM template.
An example of the application of this law for a specific case is the transformation that is illustrated in Figure4.2, where we replace B∨C with A. Notice that the generic template is matched by the example. Application of this law can be useful to improve readability of the CK, if we manage to simplify a complex feature expression. It might also be useful to improve maintainability. For example, consider the case abovementioned,
4.2 LAWS FOR REFACTORING CK 56 where in the LHS model, CommonBandC is associated with the expression B ∨ C. If we add another operation under A, we have to update this CK item. This is not needed on the RHS model of Figure4.2.
Law 3: Merge items with propositionally equivalent feature expressions
It is possible that different CK items contain equivalent feature expressions. We see an example of this situation in the LHS CK of Figure 4.3. Figure 4.6 precisely specifies, in an abstract way, a law establishing that we can merge CK items whenever they are propositionally equivalent.
'"%()*"+,#$*"--./0
1--"(-!!! !!!
"#$ %&
"#$2 (
677$#7
!!! !!!
"#$ !"#$!%
!
!"#$!$!"#%
Figure 4.6 Merge items with propositionally equivalent feature expressions template.
Law 4: Merge items with equivalent feature expressions by the FM
In a similar way that we do for Law 2, we can generalize the particular case of the previous law to specify a law stating that we can merge two CK items whenever their feature expressions are equivalent according to the FM. Figure 4.7 establishes this law.
We see that, as in the previous law,a1 anda2 are merged into the same CK item, when applying the law from left to right. When applying from right to left, it also states that, for a line that has multiple transformations, we can split them into CK items that have equivalent feature expressions according to the FM.
Suppose that we want to apply this general transformation to a specific case. For instance, in the case of the Expression Product Line FM of Figure 3.3, by Law 2, we know that we can replace Integer ∨ Double with Value Type. Since, by the FM in Figure 3.1, we know that Value Type is a mandatory feature directly connected to the root, it is equivalent to EPL. So, we can merge the two CK items into one which has
4.2 LAWS FOR REFACTORING CK 57
'"%()*"+,#$*"--./0
1--"(-!!! !!!
"#$ %&
"#$2 (
677$#7
!!! !!!
"#$ !"#$!%
!
!"!!!!"#$%!!!#$%&'
!"
Figure 4.7 Merge items with equivalent feature expressions by the FM template.
EPL as the feature expression. Figure 4.8 illustrates this example. In this particular case, it might not be helpful to apply the law from left to right, it might not be helpful for understandability of the RHS CK model. Then, we can use the same law, from right to left, to revert to our original LHS CK. Application of this law from left to right can be useful in the context of improving long CK models, so we can reduce its size, thus, reducing cost for maintenance. Reduction of a CK might also be useful in the context of verification of CK-based SPLs, where we can optimize the verification process, by simplifying the CK.
'"%()*"+
,#$*"--./0
1--"(-!!! !!!
!"#
"$%&$'()*'+',- !./$0112%3)*'+',-4'560)*'+'
!
70'86$0-!./$0112%3 911081
))) )))
!"#
"$%&$'()*'+',-!./$0112%3)*'+'
4'560-:;/0 4'560)*'+'
!"#$%
!"#$%!!!!"!"#!"!4'560-:;/0!
Figure 4.8 Example of Law 4: Equivalent Feature Expression.
Law 5: Duplicated Assets
An asset might be duplicated in a CK. This law states that we can merge CK items with duplicated assets. Figure4.9 establishes this law, where, from left to right, we merge two CK items into a single item, creating a new feature expression. This feature expression is expressed as the disjunction of the previous feature expressions. Applying the law from
4.2 LAWS FOR REFACTORING CK 58 right to left, we can split an or feature expression into CK items that have duplicated assets.
'"%()*"+,#$*"--./0
1--"(-!!! !!!
"#$ %&
!
'"%()*"+,#$*"--./01--"(-!!! !!!
"#$+!+"#$2 %&
"#$2 %&
Figure 4.9 Duplicated Assets template.
Figure4.10illustrates an example of the application of this law, still using the EPL CK from Figure3.3. We use this law from right to left to transform the CK item associating Integer∨Doublewith Value. ApplyingLaw 5 in the RHS model, we split this CK item into two separate items with the same assets associated to each part of the disjunction.
The semantics of the CK is preserved, since in the LHS CK, we still have that if only one of the options — (Integer orDouble) — is selected, Valueis yielded in the resulting set.
When applying from left to right, this law improves readability of CK models, since we avoid duplication of assets names in the CK.
!
!"#$%'"%()*"+
,#$*"--./0
1--"(-!!! !!!
'!"#$%&!'!
()#*"$ +!"#$%&!'!
,$!-#.$/
012.$334)5 633$-3
%%% %%%
75-$8$./!/()#*"$ +!"#$%&!'!
Figure 4.10 Example of Law 5: Duplicated Assets.
Law 6: Dead Feature Expression
Feature Models, as we discuss in Section2.1.1, might have cross-tree constraints, which impose additional restrictions on product configurations. This might lead to dead fea-tures. A dead feature is a feature that does not appear in any product
configura-4.2 LAWS FOR REFACTORING CK 59 tion [TBD+08]. In a similar way, we can have dead feature expressions in the CK.
These expressions are called dead because, for all product configurations, they are not evaluated to true.
Figure 4.11 establishes this law, where, applying from left to right, we remove exp from the LHS CK, since from fm we deduce that it is never evaluated as true. On the other side, this law also states that, applying from right to left, we can always add a line with a dead feature expression to our CK, without altering its meaning. Although this does not seem to be useful in practice, it might be useful for theoretical results, such as the completeness of laws proposed, in the same way that a law that adds a dead feature is useful in the completeness derivation of laws for FMs in [GMB08].
'"%()*"+,#$*"--./0
1--"(-!!! !!!
$;5 !"
!
!"!!!!"!#$%
&
$;5 !"
!"
!%
Figure 4.11 Dead Feature Expression template.
Figure4.12 illustrates an example of the application of this law. Suppose that, in the EPL CK from Figure 3.3, we have a CK item associating the feature expressionInteger
∧Double to the IntAndDbl asset. This feature expression is never evaluated to true for the FM in Figure 3.1. According to this FM, there is no product configuration that has both Integer and Double selected at the same time. Therefore, we can apply the law from left to right and remove this item from the LHS CK. Since this CK item has no effect in the CK evaluation in the LHS CK, evaluation of the RHS CK for all product configurations yields the same sets as evaluation for the LHS CK.
Law 7: Change Order
This law states that the order in which we write the CK has no effect on its semantics, since, in this case, we are dealing with assets selection only, not with complex transfor-mations that might need some sort of ordering between them. Figure 4.13 establishes