In a system that processes user commands, you notice that the if-else chain for command processing has become excessively long and difficult to manage. Which refactorization strategy might be most effective? 

  • Introduce a command pattern 
  • Split the chain into functions 
  • Use a nested if-else 
  • Increase the use of comments
The Command Pattern encapsulates a command request as an object, allowing the parameters to be passed, queued, and executed at a later time. This makes the code modular, maintainable, and ensures decoupling between classes that invoke operations from those that perform operations.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *