I am creating a plugin that uses a metric to determine a score on one page and allows the user to click through to see a more detailed breakdown of the score on a separate page.
The trouble is: I can't decide whether it is best to re-implement the logic used to derive the initial score when generating the breakdown. On the one hand, the same logic should be used in both cases. The score should be the same; the breakdown code should just run some extra queries to give more detail on what constitutes the score.
Re-implementing (what should be) the same logic using new methods could run afoul Segal's law: "A man with a watch knows what time it is. A man with two watches is never sure." If anything changes about how the metric is calculated then the two scores (the one shown initially and the one in the breakdown) could diverge - at least the logic would need to be updated in both places.
On the other hand, it seems cleaner to have methods that have a single purpose (or as few as possible). Running through the same methods means using a flag to determine whether we are generating the simple score or the breakdown. Adjusting the behaviour of the methods in this way, depending on the flag, makes the code more complex, harder to see the purpose of, and harder to maintain. The score that is calculated should be the same. If it is not, then that points to a fault in the logic. One solution would be to create new methods to calculate the breakdown and then create some unit tests to check that the scores match. That provides the extra benefit of revealing flaws that would otherwise be hidden (a man with two watches is more likely to know when a time-telling device is unreliable).
I am not really asking for an answer in my specific case as I am sure it will depend on the details (how much extra work is being done in the breakdown, and so on). The question is: What should I consider when deciding how to re-use application logic in a situation like this?