I need to determine the average miles per hour for a trip and an object containing a list of trips. I'm thinking of two approaches. First approach, have a MphCalculator class that I would inject into each class such as
public class MphCalculator {
public BigDecimal calculateMph(int durationSeconds, BigDecimal miles) {
//calculate speed
}
}
The second approach would be for each object to have their own reference to an MphCalculator class such as
public class SpeedCalculator {
final int durationSeconds;
final BigDecimal miles;
public SpeedCalculator(int durationSeconds, BigDecimal miles) {
this.durationSeconds = durationSeconds;
this.miles = miles;
}
public BigDecimal calculateMph() {
//calculate and store speed
}
}
The second approach to me seems more Object Oriented, but it also seems as though I may be creating unnecessary objects. If anyone could provide some pros/cons then that'd be very helpful! Also, this is my first question, so if I could improve this post in any way let me know.