I'm learning design patterns and I am confused because I don't know what pattern is best for this situation:
I have String and this String may be various. It may be "123abc", "abc123", "abcdfe" or "123456" and only like those string's.
public void doSomething(String variousString) {
StringType type = checkType(variousString);
if(type==StringType.Mixed) doMixedAction();
if(type==StringType.OnlyLetters) doOnlyLetterAction();
if(type==StringType.OnlyDigits) doOnlyDigitsAction();
}
Firstly I thought about Strategy pattern but I think that It doesn't match here. Now I think that Chain of Responsibility is matching here very well.
What is the best pattern for remove if statements in this situation? What are your opinions?
Aucun commentaire:
Enregistrer un commentaire