I want to model some mathematical structures. For this purpose I want to define an interface, an abstract class for general purpose algorithms and concrete implementations of that class (I have three in mind).
Now the situation arises that the general purpose algorithms that do not depend on the details of the datastructure, but only depend on the three fundamental methods int Length()
, Set<int> DescentSet()
and int[] Normalform()
. Normally this means that I would use the method template pattern, i.e. I would make these three methods abstract and let the concrete implementations deal with it.
But: Those methods are interdependent. I really only need any one of them to define the other two. So I really should only make one of them abstract. But the three intended implementations are exactly different on which of these they would prefer to be the abstract method: The first has an easy time computing Length
, the second can easily compute DescentSet
and the third gets Normalform
for free.
What is the most clean solution for this situation?