tags:

views:

1259

answers:

2

Should a wrapper class be an instance class or a class with shared members? I need to create a wrapper class around a 3rdparty library, exposing just 2 functions and hiding all the complexity of the 3rd party class.

+1  A: 

That really depends on the 3rd-party library... if it makes sense to have multiple separate instances of the lib with separate state, then an instance approach is suitable. If it is stateless methods, then a static/shared API would be appropriate.

Unless you need it to implement an interface, in which case it has to be instance-based.

Marc Gravell
+2  A: 

Simple rule here. If the class in the third-party library is an instance class, make your wrapper an instance class; if the class in the third-party is a static class, make your wrapper a static class. The idea of wrapper classes is generally to mimic structure, but simply hide complexity/advanced/unwanted functionality.

The only exception of which I can think is the case that the third-party library is poorly designed, and an instance class should really exist as a static class. Of course, if you are wrapping the functionality at such a level that your wrapper function instantiates a new class, it should really be declare within a static class.

Noldorin