T
Tony Johansson
Hello!
Below I have method MostPowerful which is located in class SportsCar.
As you can see the fomel parameter for method MostPowerful is carCompare of
class SportsCar.
Because this method MostPowerful is a member of class SportsCar
can I use the field directly for the passed SportsCar object in
this way "carCompare.horsepower".
Now to my question. I have two choices. I wonder which is best according to
OOP.
1. Use the field directly as I have done by using this statement
"carCompare.horsepower"
2 Or use a property to get the horsepower. Like carCompare.GetHorsepower or
somthing similar
Is the performance between using 1 or 2 about the same?
public SportsCar MostPowerful(SportsCar carCompare)
{
if (carCompare.horsepower > this.horsepower)
return carCompare;
else
return this;
}
//Tony
Below I have method MostPowerful which is located in class SportsCar.
As you can see the fomel parameter for method MostPowerful is carCompare of
class SportsCar.
Because this method MostPowerful is a member of class SportsCar
can I use the field directly for the passed SportsCar object in
this way "carCompare.horsepower".
Now to my question. I have two choices. I wonder which is best according to
OOP.
1. Use the field directly as I have done by using this statement
"carCompare.horsepower"
2 Or use a property to get the horsepower. Like carCompare.GetHorsepower or
somthing similar
Is the performance between using 1 or 2 about the same?
public SportsCar MostPowerful(SportsCar carCompare)
{
if (carCompare.horsepower > this.horsepower)
return carCompare;
else
return this;
}
//Tony