You know that feeling that you're class design is messed up and maybe that's code you're smelling? Help me fix this.
-
I have a List.
-
Each RoadTrip in the list has a RoadTrip.Start and RoadTrip.End, so it's easy to determine the distance to be traveled in the trip. (distance from start to end)!
-
But I frequently need to know various things related to the TOTAL travel distance including travelling from my current position to RoadTrip.Start. (TotalDistance = Distance(CurrentPosition,Start)+Distance(Start,End). Total miles, gas needed, time calculations, states to avoid, etc. I don't want to set my current position as a property in every RoadTrip within the list!
-
If possible, I'd also like to avoid passing my current position into each of the RoadTrip methods that calculate those various items every time I call those methods... it makes the outer code ugly and there are a lot of methods that need CurrentPosition!
-
But every RoadTrip in my list shares the same CurrentPosition. It seems like setting this property at the list level would be perfect.
Is there a good design pattern that allows me to set my current position at the List level, but retrieve calculations based on that parameter from Trip methods? If not, what do you recommend?
(Class names changed to protect the innocent. I am not wanted in any states and can roadtrip arbitrarily)
Thanks!
Aucun commentaire:
Enregistrer un commentaire