## 3 Extract Class Refactoring Based on Clients
### A Theoretical Model  
The proposed approach can be theoretically modeled based on the following set of definitions. **Definition 1** (Classes). : \(S=\{c_{1},c_{2},\ldots,c_{n}\}\) _is the set of classes that composes an object-oriented system, where \(n\) is a finite number of classes within the set {S}._  
For example, the set of classes of the system \(S\) shown in Figure 3 is \(S=\{A,B,C,D,E\}\). **Definition 2** (Methods of a class). : _Let \(c\in S\). Then \(M(c)=\{m_{1},m_{2},\ldots,m_{k}\}\) is the set of methods implemented in the class \(c\), where \(k\) is a finite number of methods within the set \(\{M(c)\}\)._The set of methods of the class \(A\) shown in Figure 3 is \(M(A)=\{a1,a2,a3,a4,a5,a6\}\). **Definition 3** (Clients of a method). : _Let \(c\in S\) and \(m\in M(c)\). Then, \(Client(m)=\)[\(c^{\prime}\in S-\{c\}\mid\exists m^{\prime}\in M(c^{\prime})\) and \(m^{\prime}\) invokes or may, because of polymorphism, invoke [\(m\)] that is the set of clients of \(m\)]._  
For Example, \(Client(a1)=\{B,C,D\}\) is the set of clients of the methods \(a1\) in the class \(A\) shown in Figure 3. The classes \(B\), \(C\), and \(D\) are clients of the method \(a1\) because each of them has a method that invokes the method \(a1\) (i.e., \(b1\), \(c1\), and \(d1\) for \(B\), \(C\), and \(D\), respectively). **Definition 4** (Degree of client-based similarity between two methods). : _Let \(c\in S\) and \(m_{i}\), \(m_{j}\in M(c)\). Then, the degree of client-based similarity between the method \(m_{i}\) and the method \(m_{j}\) is defined by_  
\[Sim_{clients}(m_{i},m_{j})= \begin{cases}\frac{|Client(m_{i})\cap Client(m_{j})| }{|Client(m_{i})\cup Client(m_{j})|}&\quad\text{ iff }|Client(m_{i})\cup Client(m_{j})|>0,\\ 0&\quad\text{ Otherwise;}\end{cases} \]  
The value of \(Sim_{clients}(m_{i},m_{j})\) ranges from \([0-1]\) where \(0\) means the methods share no common clients while \(1\) refer to the methods that have the same set of clients. Consider the methods \(a1\) and \(a2\) in the class \(A\) shown in Figure 3. The clients of \(a1\) is \(Client(a1)=\{B,C,D\}\) and the clients of \(a2\) is \(Client(a2)=\{B,C,E\}\). Using these two sets, we compute the degree of client-based similarity between the two methods as follows,  
\[Sim_{clients}(a1,a2)=\frac{|Client(a1)\cap Client(a2)|}{|Client(a1)\cup Client (a2)|}=\frac{2}{4}=0.5.\]  
Figure 3: A hypothetical system \(S\) consisting of \(5\) classes. The figure shows the methods of the class \(A\) that are used by the other classes (the clients of \(A\)). The unnecessary implementation details of the classes and methods are hidden. **Definition 5** (Degree of client-based similarity between a method and a set of methods). : _Let \(c\in S\), \(m\in M(c)\), \(SM\subset M(c)\), and \(m\
otin SM\). Then, the degree of client-based similarity between the method \(m\) and the set of methods \(SM\) is defined by_  
\[SimMethodWithSet_{clients}(m,SM)= \begin{cases}\frac{\sum\limits_{x\in SM}Sim_{ clients}(m,x)}{|SM|}&\text{ iff }|SM|>0,\\ 0&\text{ Otherwise};\end{cases} \]  
For example, the degree of client-based similarity between the method \(m5\) in the class \(A\) shown in Figure 3 and the two methods \(\{a1,a2\}\) as follows,  
\[SimMethodWithSet_{clients}(m5,\{a1,a2\}) =\frac{Sim_{clients}(a5,a1)+Sim_{clients}(a5,a2)}{|\{a1,a2\}|}\] \[=\frac{0.333+0}{2}\] \[=0.167\]  
**Definition 6** (Cohesion Based on Client Similarity). : _Let \(c\in S\). Then, the Colhesion Based on Client Similarity (CBCS) for the class \(c\) is the ratio of the summation of the client-based similarity between each pair of methods in the class \(c\) to the total number of pairs of methods in \(c\).