I have below implementation to find cardType.
public enum CardType{
CREDIT,DEBIT , LOYALTY;
}
class CardTypeChecker{
public String getCardTypeInString(CardType cardType) {
return convert(cardType)
}
protected String convert(CardType cardType) {
switch (cardType) {
case CREDIT:
return CardType.CREDIT.name();
case DEBIT:
return CardType.DEBIT.name();
case LOYALTY:
return CardType.LOYALTY.name();
default:
throw new IllegalArgumentException("Provided CardType is NOT available.");
}
}
}
Now i want to know how i can apply design pattern to remove this code smell of switch statement.
Aucun commentaire:
Enregistrer un commentaire