A Global Singleton is a class of which only one instance exists within a program.

Any attempt to use non-static members of the class involves performing operations on this one instance.




public class Singleton : Object {
    static Singleton? instance;
 
    // Private constructor
    Singleton() {
 
    }
 
    // Public constructor
    public static Singleton get_instance() {
        if (instance == null) {
            instance = new Singleton();
        }
        return instance;
    }
}
 
void main() {
    Singleton a = Singleton.get_instance();
    Singleton b = Singleton.get_instance();
    if (a == b) {
        print("Equal.\n");
    }
}