0

When using an external library or API, I have noticed that each function or data structure belonging to that library or API has something in its name which discloses the API or library we are using. For example, D3DXVECTOR3 or SDL_Surface from Direct3D and SDL respectively have been named to disclose which API they belong to.

While building our own applications, I would not like to disclose which API's I have used, so is it good practice to change the name of these API structures by #define directives into some more general names? Is this a practices and used form of abstraction? Are there better ways to do such abstractions?

The Light Spark
  • 504
  • 4
  • 19

1 Answers1

0

In the OO world, the best way to do such an abstraction is through the adapter pattern.

Since you mentioned #define, I assume you are using C or C++. In both cases, you can still use this pattern if you want. Simply use a class with an abstract base class as the interface. This will add a small overhead because of the virtual function calls though. You could also consider template inheritance to bypass this issue.

Either way, I would avoid using the preprocessor as much as possible since it can quickly turn your code into a nice italian dish.

Etienne Maheu
  • 3,235
  • 2
  • 18
  • 24