Refactor case statement with polymorphism