How to use Command pattern by passing to it runtime params

前端 未结 1 1159
滥情空心
滥情空心 2021-01-26 20:10

I have functionality that I am encapsulate on diff commands using Command pattern.

I am creating the command with the information and logic it need how ever I am getting

相关标签:
1条回答
  • 2021-01-26 21:04

    The Command pattern stipulates an object that can be executed with no arguments after its creation (for example: Runnable or Callable) however, there is nothing preventing arguments from being passed during creation; so you can simply move the msg argument from the execute() method to the command's constructor.

    In a typical use of the Command pattern, commands are created in one place and executed in another. The creation logic is parameterized; the execution logic is not.

    0 讨论(0)
提交回复
热议问题