mardi 18 avril 2017

What design pattern(s) to use to encapsulate a collection of functionalities

Suppose there is a collection of commands that needs to be implemented. A command may need some input arguments and after execution, it may return some results. A few design considerations are:

  • Commands are created at run time
  • Commands creation is based on user input
  • Command inputs may be encrypted or compressed or both
  • Different commands may need to be created in ways specific for each command
  • Different commands may have different number of inputs and input types
  • Command inputs are provided at runtime
  • Result of different commands may have different types

For example, a command may be 'GetFileList' that receives a path to list its files and returns a list of files as a result. In this case, the command has a single input of type string and returns a result of type string[]. On the other hand, a command 'RenameFile' may have two inputs of type string and return a boolean value to indicate success or failure.

For object creation, I can think of the Factory and Strategy patterns but I cannot think of a good way to encapsulate results and input parameters. What design patterns can be useful for implementing this scenario?

Aucun commentaire:

Enregistrer un commentaire