❔ Best pattern to alleviate the pain of a many-to-many unit conversion program?
For example, converting gallons to any other volumetric unit and vice versa
4 Replies
assuming you don't want to just define all possible combinations and look them up from, like, a dictionary
model all the "primitive" conversions that you need as edges on a graph
with types being nodes
and your general-purpose converter can walk the graph to find the most-efficient chain of conversions to link any two types
or can identify types that can't be converted
Define conversions to/from base units
Eg liters for volume
literally solved this precise issue this way, just pick a common unit and you're gold
is what I ended up doing, either they use a fixed ratio or a custom converter where appropriate
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.