This is a basic example of the Singleton design pattern in Haxe.
class MySingleton { // read-only property public static final instance:MySingleton = new MySingleton(); private function new () {} // private constructor }
Usage
class Main { public static function main () { // this will be the only way to access the instance MySingleton.instance; // This will throw error "Cannot access private constructor" // new MySingleton(); } }