lundi 27 juillet 2015

Strategy Pattern with strategies contains similar code

In most examples, strategy pattern is usually good for compression algorithms/ codec algorithms, where these algorithm might have quite different code.

However, in my case, the statistics algorithms I want to refactor to strategy pattern, have 50% code similar or exactly the same. I was wondering how do people deal with this? If I use strategy pattern, there could be 50% of the code copied around, which is not desired. If not refactor, the code is ended up with many sets of if-else all around to handle different types of statistics algorithms. How to evaluate the trade-off? What could be other possible solutions?

Aucun commentaire:

Enregistrer un commentaire