mardi 4 septembre 2018

Is Command Pattern Applicable here?

I've a value object(VO). One of the field/property is 'sourceKey' that holds a string value.

For Example:
String sourceKey1 = "cust12/proj1/site1/images/somefile.JPG"
String sourceKey2 = "cust12/area1/site1/images/somefile.JPG"

Now I need to kinda transform this sourceKey and build up a destination key by first breaking the source key by'/' and then:
- replace cust12 by calling customer service - find customer by Id 12 and replace cust12 by customer name in the dest key.
- similarly to replace proj1 - call the project service , find project by id 1 and replace proj1 by the project name.
- and so on..

So to achieve this in a clean manner, I thought of writing commands - each command for fetching an object by calling the appropriate service(customerService, projectService etc). And then at the client level just parse the sourceString and build up a list of commands to be executed and then finally build up a destination key using the commands list.

Am I thinking in the right direction? Is command pattern the clean/OO way of doing this?

Aucun commentaire:

Enregistrer un commentaire