I know what coupling and cohesion mean.
I have got the following example and it has some maintainability issues and therefore it needs some refactoring:
The problem is, I could not relate any coupling, cohesion or any other maintainability issue other than GLOBAL VARIABLES. How can I refactor the following code without this global variables issue (because global variables increase complexity & increases the code inflexibility?!)
double value;
double min, max;
public void read()
{
do
{
value = ConsoleInput.readDouble();
}
while(value < min || value > max);
}
public double hyp()
{
double x, y;
min = 0.0;
max = 100.0;
read();
x = value;
read();
y = value;
return Math.sqrt(x * x + y * y);
}
I was thinking it to refactor like below:
public void read()
{
double value;
double min = 0.0;
double max = 100.0;
do
{
value = ConsoleInput.readDouble();
}
while(value < min || value > max);
}
public double hyp()
{
double x, y;
read();
x = value;
read();
y = value;
return Math.sqrt(x * x + y * y);
}
Does this look right? Or is there any other efficient way of refactoring this?