This is an extension of my previous question here. If I were to implement a method called getGasMileage for a Car POJO, where's the best place to keep that method. I see 4 design strategies:
- Put it in a Utility class
- Make it a
Function - Using the strategy pattern, create a Strategy interface and the implementation will be called
CarStrategy, pass the strategy object intoCarthrough the constructor and have agetMileagemethod inside of theCarclass that calls theCarStrategyobject method - Create a simple interface with a method like
double getMileage(Car car)
What would be the tradeoffs of these approaches?
Aucun commentaire:
Enregistrer un commentaire