Skip to main content
added 424 characters in body
Source Link

Both approaches are acceptable, but the one based onusing a Dictionary feels cleaner to me, and brings some advantages at no significant cost.

  • A Dictionary will detect a duplicate key, whereas it could be easily overlooked in an if-else construct, leading to a possibly baffling bug

  • It could be modified in run-time, eg. for debugging purposes.

  • It's more flexible: it could be injected from outside, easily refactored towards a DI-based approach etc.

This being said, it could be overengineering for simple cases. It's hard to say without knowing broader context. All info you've provided is that there's 5 cases, which is quite a few already, and it makes me guess there's a chance for more to come; if all I knew was that there's 2 or 3, I would say keep it simple.

Both approaches are acceptable, but the one based on a Dictionary feels cleaner to me, and brings some advantages at no significant cost.

  • A Dictionary will detect a duplicate key, whereas it could be easily overlooked in an if-else construct, leading to a possibly baffling bug

  • It could be modified in run-time, eg. for debugging purposes.

Both approaches are acceptable, but the one using a Dictionary feels cleaner to me, and brings some advantages at no significant cost.

  • A Dictionary will detect a duplicate key, whereas it could be easily overlooked in an if-else construct, leading to a possibly baffling bug

  • It could be modified in run-time, eg. for debugging purposes.

  • It's more flexible: it could be injected from outside, easily refactored towards a DI-based approach etc.

This being said, it could be overengineering for simple cases. It's hard to say without knowing broader context. All info you've provided is that there's 5 cases, which is quite a few already, and it makes me guess there's a chance for more to come; if all I knew was that there's 2 or 3, I would say keep it simple.

Source Link

Both approaches are acceptable, but the one based on a Dictionary feels cleaner to me, and brings some advantages at no significant cost.

  • A Dictionary will detect a duplicate key, whereas it could be easily overlooked in an if-else construct, leading to a possibly baffling bug

  • It could be modified in run-time, eg. for debugging purposes.