I am developing a computer vision application and I will need a classifier class. This class will be unchanged every time the application is launched and loads prepared data from disk during initialization. I want the whole program to have access to the same prepared data, and I want to block the reboot from disk after loading it.
What I was considering is to use either a static class or singleton. I'm not sure how to load data into a static class, because the path to the data file is not known at compile time - this will be a programmatic argument. So I was thinking about a singleton template, but there I don’t know how to initialize it dynamically.
My idea was this:
class Singleton {
private static Singleton instance;
private Singleton() { ... }
private static SomeDataObject data;
public static Singleton getInstance() {
if(instance == null)
instance = new Singleton();
return instance;
}
public static init(string dataPath){
if(data == null)
loadDataFromFile(dataPath)
}
}
, , .
, , , . Classifier , API, .
, singleton ?