You're doing condition on obj.type twice: to get the type and the default. Can't we merge them all in a single switch statement ?