The the Coupling Corruption Propagation is an OO metric that computed as follows:
Coupling Corruption Propagation = Number of child methods invoked with the parameters based on the parameters of the original invocation.
In the code bellow, a parent method calculateStringBuildSpeed invokes a child method called buildString with the parameter length. The method buildString then calls three child methods of its own callStartTime, callEndTime, and reportResult. The methods callStartTim and callEndTime do not take any parameter. Therefore, they are effectively immune to any coupling effects that originate from calculateStringBuildSpeed. However,
reportResult takes one variable stringLength that is calculated from the original length variable. If the variable is ever compromised (i.e., it becomes null, has a value that exceeds the int range, or contains a value that reportResult cannot use), then reportResult method could indirectly be corrupted from calculateStringBuildSpeed. Therefore, the coupling corruption propagation is 2 in the following code.
So how can I modify the following code so that the Coupling Corruption Propagation will decrease for example into 1 or 0
-------------------------------------------------
Public void CalculateStringBuildSpeed(double
numOfElements)
{
buildString (numOfElements);
}
.
.
.
public String buildString(double length) {
String result = "";
int startTime;
int endTime;
int stringLength = (int) length;
startTime = callStartTime();
System.out.println("Starting Now");
for (int i = 0; i < stringLength; i++) {
result += (char)(i%26 + 'a');
}
endTime = callEndTime();
reportResult(startTime,endTime,stringLength);
return result;
}
---------------------------------------------------------