## 3 Extract Class Refactoring Based on Clients
### Our Approach of the Extract Class Refactoring  
The main steps of our approach are shown in Figure 4. Given a class to be refactored, we first extract the methods of the class. Then, we determine the clients of each method using Definition 3. Once we have the clients of each method in the class, we compute the degree of client-based similarity between each pair of methods in the class using Definition 4 and store the results in a \(k\times k\) matrix where \(k\) is the number of methods in the class. The entry \([i][j]\) of the \(k\times k\) matrix holds the degree of client-based similarity between the method \(m_{i}\) and the method \(m_{j}\). Next, Algorithm 1 is applied which takes an input the set of methods in the class to be refactored, the \(k\times k\) matrix that holds the degree of client-based similarity between each pair of methods, and a threshold value. The algorithm returns a clutter, i.e., a family, of subsets from the input set of methods as an output. The algorithm classifies the input set of methods into different subsets of methods based on the client-based similarities between the methods. The input threshold value is used to determine if a method to be classified is added to an existing subset of methods or added to a new subset. Therefore, if the threshold value is high and the client-based similarities between the methods of the class to be refactored are generally low, each method will probably be added into a different subset, which meanseach extracted class will have only one method. To overcome this issue, the median of the non-zero client-based similarities of all pairs of methods in the class can be chosen as a threshold value. Finally, Algorithm 2 is applied to avoid the extraction of classes that have a small number of methods (e.g., one method). The algorithm takes as an input the clutter \(F\) resulting from Algorithm 1, the minimum number of methods that each extracted class can have, and the \(k\times k\) matrix that holds the degree of client-based similarity between each pair of methods. The algorithm returns as an output a clutter of subsets such that each subset has a number of methods that is equal or more than the input minimum number of methods. Algorithm 2 merges any subset \(X\in F\) that has less number of methods than the input minimum number of methods with the subset \(Y\in F-X\) that has the highest average of the client-based similarities. Each subset in the output of Algorithm 2 represents a candidate class that can be extracted from the class to be refactored. The attributes as well as private and protected methods of the class are not considered in this work. However, they can be automatically distributed among the extracted classes suggested by our approach based the use of the attributes as well as private and protected methods by the public methods in the  
Figure 4: An outline of the main steps of our approach. extracted classes. Each attribute can be added to the extracted class that has the highest number of methods that use the attribute; similarly, private and protected methods are distributed in the same way. Our approach automatically suggests the set of classes that can be extracted from a given class. A software engineer may evaluate the suggested classes and approve them or make some changes to them by moving the methods and attributes between suggested classes. ```
Input: (1) \(M(c)\): the set of methods of the class \(c\) to be refactored. (2) Threshold: a threshold value.