mardi 13 septembre 2022

What is the best way to have different code for different clients or platforms?

What is the best way (or what are the options available) to have different code for different clients or platforms?

In my company we sell a product that can be customized per client and runs in different platforms, and I don't really know how to manage this.

Most of the design patterns I've researched feel like they exist to choose between different components in run time, however I don't need that, and they suffer from the same problems I feel like.

Example problems

  1. Client A asks us to add X feature.

  2. Client B asks us to make a check somewhere mid-function.

  3. Different platforms have different APIs, but not too different from each other so we can reuse code.

  4. Platform A has a bug that we need to workaround.

We relese our binaries and they run on end machines and servers.

Current solutions:

Add a runtime check

The code becomes insanely cluttered, noisy, and slower than it should be. Lots of if setting is set and if platform == X. The performance part could be solved by #ifdefs but the rest of the problems remain.

... Or if the client source code ends up becoming very different

Maintain a whole different project (repository)

This is terrible. There are many versions with the exact same code with ever so slightly checks here and there, the same code with just another api call, etc.

Different files that get resolved in build times

Some of the code is the same between files, some isn't, who knows. At least it's on the same project...

Possible solutions:

These are the solutions that I have come up with. I don't like any of them.

For 1. I really don't know. If it were modular enough and well decoupled I wouldn't really mind a new project that took the main codebase as a dependency, but it's not the case. We're working with legacy code here.

For 2. Try really hard to refactor the check out of the common function and then hide the client-specific code behind an interface. If we can't well tough luck.

For 3. This is the easiest one to overcome, this is what interfaces were created for.

For 4. I'm out of ideas here. Try the same as for 2.?

How to add this to the source control?

What are the common approaches?

Aucun commentaire:

Enregistrer un commentaire