Singleton concept is basically implemented when we require to use a single instance of a class throughout the application. For this we follow some rules.
1. We don't allow any class to create the object of the singleton class except the class itself for which we need to make the constructor the class private.
private StudentRecordController(){}
2. Then again we create the object of the singleton class in the same class within a method which is your getController method but strictly checking that not more than one object is returned from that method so that whenever that method is called from any other class it always returns the same object of that class.
public static StudentRecordController getController() {
if (object == null) { //checks here whether the object of the class has already been made or not.
object = new StudentRecordController();
}
return object;
}
3. To check the for the same object the reference varible we are using is "object" as mentioned above. That should be static and private so that whenever we access that particular variable it should always return the same object due to its single copy property.
private static StudentRecordController;