Replace explicit conditionals with polymorphism