I have a service that handles different client types. There are a lot of service classes that differ in minute ways in the way they process different clients. For the most part these classes contain logic that is common to all clients, however there are places with logic specific to clients.
I understand I could use a Factory to return a set of objects for client specific logic, or use the Template method to have concrete implementations of an abstract class for different clients -- the problem with these approaches is that there are a lot of minute branching decisions that have to be made based on the client throughout the code, and these minute branching decisions are trivial, unconnected to each other, and they don't warrant separate classes. Is there a design pattern to elegantly implement this?
class Service {
void process() {
//....
if (client1) doStuff1();
if (client2) doStuff2();
//....
if (client1) name = "xyz";
else if (client2) name = "abc";
//....
if (client1) sortasc();
else sortdesc();
//....
if (client2) processx();
else if (client3) processy();
}
}
Aucun commentaire:
Enregistrer un commentaire