質問

In my project I use a 3rd party library which is constantly changing. I have a wrapper class (Bridge pattern + Pimpl pattern) for this library. So none of my sources except wrapper implementation sees that library. This library has an Options struct, e.g.

struct Options {
  double distance;
  double weight;
  int num_rabbits;
  // etc
};

I want this struct to be available in GUI module, to build a dialog that allows to set these options. Do I need to create a wrapper struct for it? E.g.

struct MP_ThatLibOptions {
  // exact member copy
  double distance;
  double weight;
  int num_rabbits;
  // etc
};

Or shall I directly include that struct header into my sources?

The drawbacks of wrapper are: copy-paste, additional code for converting between structs. The drawbacks of direct include are: breaking the pimpl idiom.

May be there are any other solutions for this problem?

Also I want to emphasize that the 3rd party library is constantly changing, so I must adopt my sources to support every new version of the library.

役に立ちましたか?

解決 2

As I use Bridge + pimpl patterns I've decided to totally hide the 3rd party library.

他のヒント

The Options struct appears to be part of the public API, and not the private implementation that the pimpl idiom is design to hide, so it would seem that you should be including the header in your sources.

If you do this, the only code that will be liable to breakage when the 3rd party code changes is that code which uses the members of the Options struct directly, but presumably when that changes, your code needs to change appropriately anyway since that sounds like it would be an API change, so seems like you're covered.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top