• No results found

Design Composition Module

A Case-Based Approach for Reuse in Software Design

4.3 Design Composition Module

The Design Composition module generates new diagrams by decomposition and com-position of cases. The input data used in the comcom-position module is an UML class diagram, in the form of a package. This is the designer’s query, which usually is a small class diagram in its early stage of development (see Figure 4.24). The goal of the composition module is to generate new diagrams that have the query objects, thus providing an evolved version of the query diagram. Generation of a new UML design using case-based composition involves two main steps: retrieving cases from the case library to be used as knowledge sources, and using the retrieved cases (or parts of them) to build new UML diagrams. In the first step, the selection of the cases to be used is performed using the retrieval algorithm and the similarity metrics described in section 4.1. The adaptation of the retrieved cases to the target problem is based on two distinct strategies: best case composition, and best complementary cases composition. The next subsections describe these two composition strategies.

Figure 4.24: An example of an class diagram in the early stages of development.

4.3.1 Best Case Composition

The idea of the best case composition is to select the case most similar with the problem, use what this case has in common with the problem, and try to complete it using pieces of other cases.

The best case composition algorithm is shown in figure 4.25. The algorithm starts by retrieving a set of similar cases from the library (line 1). Then the retrieved

1. RetrievedCases ← Retrieve cases from the Case Library using P roblem 2. BestCase/M apping ← Select the best case and map it to the problem 3. N ewCase ← Use BestCase, M apping and P roblem to generate a new case 4. Remove BestCase from RetrievedCases

5. WHILE N ewCase does not map all the P roblem objects AND RetrievedCases 6=? DO 6. SelectedCases ← Search RetrievedCases for cases with unmapped problem objects 7. SelectedCase ← Select the best one, the one with more unmapped problem objects 8. N ewCase ← Complete N ewCase with SelectedCase

9. Remove SelectedCase from RetrievedCases 10. ENDWHILE

11. Return N ewCase

Figure 4.25: The best case composition algorithm.

case most similar to the problem is mapped to the problem objects (line 2). The mapped objects in the case are transferred to a new case (line 3). If this new case maps successfully all the problem objects, then the adaptation process is finished (the while conditions in line 5). Otherwise it selects the retrieved case, which best complements the new case (in relation to the problem, see lines 6 and 7), and uses it to get the missing parts (line 8). This process continues while there are unmapped objects in the problem definition. In the end it returns the generated case (line 11).

Note that, if there are objects in the used case that are not in the problem, they can be transferred to the new case, generating new objects, but only if the mapped objects depend on them.

An UML object A (package, class or interface) depends on an object B, if there is a relation between A and B, such that:

• A is a specialization of B (there is a generalization from A to B), or

• A is a realization of B (there is a realization from A to B), or

• A depends on B (there is a dependency relation from A to B), or

• A is associated with B (there is an association between A and B).

4.3.2 Best Set of Cases Composition

The idea of this strategy is to get the best complementary set of cases, and try to build a new diagram using these cases. The algorithm for this strategy is described in figure 4.26. The best set of cases composition approach starts by retrieving and matching each retrieved case to the problem (line 1 and cycle for in lines 2 and 3),

CHAPTER 4. CBR Engine

1. RetrievedCases ← Retrieve cases from the Case Library using P roblem 2. FORRetrievedCase in RetrievedCases Do

3. M apping ← Map RetrievedCase to P roblem 4. ENDFOR

5. CaseSets ← Create the sets of complementary cases based on each case mapping 6. BestSet ← Select the best set from CaseSets, this is the set whose mapping has

the best coverage of problem objects 7. N ewCase ← Generate a new case using the BestSet 8. Return N ewCase

Figure 4.26: The best set of cases composition algorithm.

College

University Department

1..* 1..*

Figure 4.27: An example of a class diagram representing a problem (P1 ) .

yielding a mapping between the case objects and the problem objects. This is used to determine the degree of problem coverage of each case (line 5), after which several sets of cases are constructed. These sets are based on the combined coverage of the problem, with the goal of finding sets of cases that globally map all the problem objects. The best matching set, the one with best problem coverage (in case of a draw the sets with less elements are chosen), is then used to generate a new case (line 6 and 7). Finally it returns the generated case (line 8).

4.3.3 A Design Composition Example

This example provides an illustration of the design composition mechanism. Suppose that the class diagram of figure 4.27 is used as problem (P1 ) for design composition.

The first step is to retrieve relevant diagrams and rank them. The retrieval algorithm starts by the package synset of P1, which is the synset corresponding to University.

Suppose that the algorithm retrieves two cases: Case1 corresponding to the diagram of figure 4.28, and Case2, which corresponds to the class diagram of figure 4.29. These cases are then ranked by similarity to the problem, which gives Case1 a score of 0.25 and Case2 0.7.

The next step is to build a new case using the composition strategies. We selected the best case composition strategy to generate the new case. The first thing that the algorithm does is to create a new case, which is a copy of P1. Case2 is selected

School

Figure 4.28: A class diagram representing part of a school information system (Case1 ).

College

Figure 4.29: Class diagram of Case2 (an University).

due to its higher similarity with the problem. The design composition algorithm maps University and College in Case2 to P1, transferring the mapped case objects to the new case. Then, the objects of Case2 that were not mapped are transferred to the new case, but only if mapped objects depend on them. After these operations, the problem has an unmapped object, which is Department. Case1 has an object (SchoolDepartment) that has the same classification as Department. These two ob-jects are mapped completing the new case. The resulting diagram is presented in figure 4.30.

Note also that all additional objects from Case2 have been transferred to the new case because they depend on the mapped objects. Other aspect, is that the mapping of Case1 with the problem added two additional objects (Student and Teacher from Case1 ), which already existed in the new case (from Case2 ). These two additional objects were merged with the corresponding objects yielding the new case.

CHAPTER 4. CBR Engine

Figure 4.30: The solution generated by the design composition mechanism.