I don't know if there actually is one design pattern, or several together, or maybe what i'm asking is anti-pattern.
Context (simplified) : my company sells SaaS services (through an API) to several clients, which in turn sells this service to end users. Each client uses the service, but some want custom behaviours in several features. Obviously, the custom behaviour should only occur for that specific client. The end user is linked to one specific client, so when using the service, we know which client identifier it is, so which behaviour to have on the requested feature.
My question is : by keeping only one code base, how do I manage different behaviours depending on the client identifier ?
The current implementation is obviously the naive and dirty one (simplified) :
function someFeature() {
// common code
if(clientId === 'someClient') {
// does something
} else if(clientId === 'otherClient') {
// does something else
} // else if ... for every other custom behaviour, or on other parts of the feature
// common code
}
I've read about design patterns but they all seem to be focused on parts of my problem, and I don't see how to use them all together ...
If I had to dig a solution I would probably go with an implementation of Bridge and a Factory to instanciate various classes (for each client) which would implement a same feature differently (each clients' custom behaviour). With that in mind, when a user wants to use a feature, the approriate class, thanks to the factory, would be instatiated and used with the desired custom behaviour.
This implementation looks like the correct way to do it but I think it would encourage duplication of code (for the "common code" bits), and would require the programmers to create maybe thousands of new interfaces/classes for each features multiplied by each client's custom behaviour, sometimes just for a simple line of custom code.
What do you think would be the proper way to solve my problem ?
clientId
comes in from the outside, you still will have to consult it in order to build the right sub class...