I've created working setters/getters for an application, that will use a few different classes. This classes will use one class, that will store all data. I know, when I will use a standard constructor of container class, I'll get tons on nulls, due to different instance of container class.
I've created container class within a singleton, that works, but I wanted to ask if anything could be done better, or if this code follow the best practice.
public class Container {
private String appName = null;
private String appOwner = null;
private Container() {
System.out.println("Start");
}
private static class SingletonHolder {
private final static Container INSTANCE = new Container();
}
public static Container getInstance() {
return SingletonHolder.INSTANCE;
}
public String getAppName() {
return appName;
}
public void setAppName(String appName) {
this.appName = appName;
}
public String getAppOwner() {
return appOwner;
}
public void setAppOwner(String appOwner) {
this.appOwner = appOwner;
}
}
Sample class, that will use this container:
public class SecondClass {
Container ctn = Container.getInstance();
}
Right now, when I use in main class:
ctn.setAppOwner(owner);
I get a proper value in any other classes, when I call this:
Container ctn = Container.getInstance();
ctn.getAppOwner();
Is that a good approach?