0

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.

bumped to the homepage by Community yesterday

This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.

  • 1
    It might interest. Which one do you think describe better your case? Gateway or Facade? – Laiv Mar 25 at 21:37
  • Canonical XKCD: xkcd.com/927 – Doc Brown yesterday
  • Note that your question "Is there a pattern" only leads to "yes, your task has a name" - but that will in no way help you to accomplish the task. – Doc Brown yesterday
0

I think what you're looking for is the Facade pattern (https://en.wikipedia.org/wiki/Facade_pattern).

Basically, you create a friendly, front-facing API for your users/developers to call.
When the facade API is called, it translates the call into one or more calls to one or more of the "source" APIs, then passes the results (maybe with some more translation) back to the caller.

Essentially, it masks the complexity of the source APIs (and gives you an opportunity to standardize the request and response data, formats, etc.).

  • 1
    This is correct. Unfortunately, there is no silver bullet that will do this for the OP - they will need to manually program this themselves. – Victor Parmar Mar 25 at 14:54
0

It seems a mix of Abstract Factory Pattern and Façade. You would have a common interface (abstract class) and families of concrete classes which implements the API for each provider. Through the factory, you could select which provider to use.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.