G
Guest
Lets consider a class called Currency. This class must be the responsible for
taking care of all calculations over currency exchanges, in such a way that I
pass values in Euros and it returns the converted value in Dollar for
example...
Well, I might do this in 2 ways, as below:
1) I create a method like this:
double ConvertValue (double OriginalValue) {
// here I compute the value
return ComputedValue;
}
2) I create the method like this:
bool ConvertValue (double OriginalValue) {
// here I load private attribute ConvertedValue
ConvertedValue = ComputedValue
return OK;
}
In the first case I returned value in the method itself, in second case I
loaded the value in a private attribute. In second case the client method
would have to execute ConvertValue and then ask for property value. In first
case, the returned value would come in the method return itself....
What is the best approach? Are there special situations in which we should
use one or another??
taking care of all calculations over currency exchanges, in such a way that I
pass values in Euros and it returns the converted value in Dollar for
example...
Well, I might do this in 2 ways, as below:
1) I create a method like this:
double ConvertValue (double OriginalValue) {
// here I compute the value
return ComputedValue;
}
2) I create the method like this:
bool ConvertValue (double OriginalValue) {
// here I load private attribute ConvertedValue
ConvertedValue = ComputedValue
return OK;
}
In the first case I returned value in the method itself, in second case I
loaded the value in a private attribute. In second case the client method
would have to execute ConvertValue and then ask for property value. In first
case, the returned value would come in the method return itself....
What is the best approach? Are there special situations in which we should
use one or another??