There is an obvious code duplication. Just instantiate a class first, and then do the `if-then-else`