I'm trying to help my friend with his project and whilst doing that I saw that he has 2 almost similar algorithms implemented.
My first thought was to use Template pattern.
public abstract class Template {
calculate();
save();
}
and so on. However in second algorithm calculate()
and save()
need additional parameters. Code inside both methods in both algorithms is duplicating in 90%.
Lets say in first algorithm I need only longitude and in second longitude and latitude.
Thus, the only way to make it with Template pattern is to create some object with longitude and latitude and to pass it in both algorithms. However, I don't like this solution because of this second parameters that will be "null" in the first algorithm.
Maybe I don't see some better, cleaner way to resolve this problem?
Aucun commentaire:
Enregistrer un commentaire