Design pattern for wrapping multiple apis into single api

architectural-patternsdesign-patternspatterns-and-practices

I have 3 different libraries that provide depth data as well as gesture information. I need to wrap these libraries into a single simpler to use for user api. The apis I am trying to wrap provide a set of utilities as well as information that are not equal. The core data such as depth images or color images are provided but tracking can have different method or amount of information provided may differ. For example, one api provides a list of hands being detected and each hand has internally an orientation info(l/r). Another api provides l/r hand objects with NULL if not found and info if found.

I need to wrap these apis into a single api in the same language(c++) that allows user to have to write way less code to get the core functionalities. Is there a pattern that provides best-practices for such a task? Or any examples in industry that do something similar? I understand that single tight-knit apis are better than a large api, but for my current use-case, a large api makes sense, so I need to do that.

Best Answer

As others have said, the Façade pattern is an obvious way to go. To add to the answers thought, I'd like to say, you need to think carefully about the semantics of the API you are trying to wrap when creating the simpler Façade. Syntax is the easy part.

For example, your API may require an initialisation function followed by functions which actually do the bit you are interesting in, followed by a tear down before allowing a new init. If you abstract away the init part are you potentially adding unnecessary processing with every API call (init, process, tear-down) without the user knowing that they are doing so.

Obviously, my example is completely hypothetical, but it just goes to illustrate that you need to think carefully about how the API is simplified so unintended consequences are not introduced.

Related Topic