I am currently porting a C library to Java. The C library connects to an external device and provides functions to configure the device and receive data. The core of my design is a Connection
class that encapsulates the connection to the device and provides the low-level C API mapping generated using JNA.
Since most of the C library doesn't translate that well into the OO-World of Java (Single header library containing 100+ functions) i have a couple of "Manager" classes that provide access to most of the functionality.
Creating more than one of these classes doesn't make sense, since the C library only manages one resource of everything (configuration, data-buffer, etc). So i want to implement the Singleton pattern for my Java classes (effectively also signaling the users of my new java library, that there is only ONE Manager object in the whole system).
Additionally i want to be able to configure these Manager classes using an external config file. I have never implemented a configuration utility before, so i don't really know where to put that.
Lastly ALL of my Manager classes need a reference to a Connection
object.
So i need a design that allows me to:
- Make my Java classes unique (Singleton Pattern)
- Inject my
Connection
object - Configure my classes using a config file
Any ideas?