mardi 19 avril 2016

How to handle multiple requests within each concrete command in command design pattern?

I want to use command pattern in one of my projects where I have to make multiple REST calls. I have encapsulated web method calls according to the module it belongs to. Like XYZDataManager contains all web method calls related to XYZ module.

Having said that, how is Command pattern going to fit in here? I don't want to make command classes for every single web method call. I want to preserve encapsulation I mentioned above.

One thought that came to my mind is making some enum like RequestType, inside every concrete Command class. And then we have execute(RequestType) method in Command interface. Each concrete command implements execute(RequestType) accordingly and call inner methods as decided by RequestType param.

Am I doing right? Or there can be a better way? Or using Command Pattern here is simply a waste altogether?

Is leaving complete request creation (including RequestType and which concrete command to use) to consumer code a good idea? Or should it be moved to a Factory method that abstracts this from consumer code?

Aucun commentaire:

Enregistrer un commentaire