Reputation: 76
I'm working in a project in .NET and part of it needs to communicate with a device connected through RS232 (com port) to the computer. I have received an API from the manufacturer of the device and it's written in C#.
I want to write a class library in c# and use it as a wrapper of this API in order to have all calls are centralized here and use only one instance of the API main class as it should be initialized only in the first call. (I think I must use Singleton)
The API has internal classes and enumerators, and some of its public methods request an internal class as a parameter.
My doubt is: Should I request the users of my wrapper those API internal classes as parameters or it's not a good practice to expose an API internal class outside the wrapper?
Also I'm doubting if it's a good idea to write that wrapper as the API is also written in C#, maybe I'm waisting my time?
Upvotes: 3
Views: 906
Reputation: 3416
Using a wrapper is a great idea, you're on the right track.
Wrapping will allow for code reuse, and as you mentioned you could create a singleton which will manage the object's lifetime.
About internal classes: Seems a very bad API if it exposes internal classes! This means you can't use those methods because you cannot create instances of those classes - nor will the consumer of your wrapper.
So, if indeed this is the situation with this API, you should definitely hide this mishap instead of exposing it.
Good luck!
Upvotes: 1
Reputation: 62276
It very depends on how much time/resources you gonna to invest into this project, or you can invest in this project.
The absolutely good choice would be hide completely the internal API
implementation from the consumer of you wrapper class. In this way, if you will get a new device, or a new driver for device (with a slightly different API
), or completely new device with completely different API
from different manufacturer, you will it again wrap into the your class, hiding all "low-level" implementation details from the user, which highly possible he doesn't care on..
But it could be a lot of work, depends on how big or good is written the original API
of manufacturer.
Hope this helps.
Upvotes: 3