开发者

Writing wrappers for libraries

I'm trying to write a wrapper for the third-party graphics library I'm using. I'd like to make it general enough you I could switch libraries easily if I decide to port it over to another platform or OS.

The problem is I can't really find a good enough design. Besid开发者_如何学Goes the library I'm using, I'm also following the design of two other libraries to ensure a general enough design. But there always seems to be something one lib can do the others can't.

Do you have any tips as to how I should make my code more portable (easy switching of libraries)? Maybe you can suggest a design for a graphics wrapper that's worked for you in the past.


Do you have any tips as to how I should make my code more portable (easy switching of libraries)?

This is rarely of significant value.

If you think you must ensure portability you have three choices.

  • Least Common Feature Set. Take all the libraries you think you might want to use. Write down all the classes, methods and attributes and find the smallest common subset. You have to do some thinking to match up all the various names to be sure you've got the semantics as close as possible.

    This will give you a minimal graphics implementation that must run everywhere.

    However, it will be feature-poor and your application (or wrapper) will have to do a lot of programming to fill in the missing features in a uniform way.

  • Union of All Features. Take all the libraries you think you might want to use. Write down all the classes, methods and attributes and simply add each new thing to the ever-growing list of features. You have to do some thinking to match up all the various names to be sure you've got the semantics as close as possible to avoid adding duplicates.

    This will present problems because a feature that's in one library must be implemented in all the other libraries. It's a lot of programming.

You're not the first person to have this thought and realize that it's really, really hard to do.

So what's the fall back?

Choice 3.

Pick your favorite library. Get something to work.

Based on customer demand, identify the most-demanded alternate library. Create the necessary wrapper so that your application can work with this library.

Iterate this last step until you're out of customers or the customer demand is so low that it's cheaper to fire them as a customer than it is to support them.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜