Vinh La Kiến

48 bundles
1 file3 months ago
1

Java Simple Singleton Pattern

123456789101112131415161718192021222324
class Manager { private static Manager instance; private Manager() { instance = null; } public static getInstace() { if (instance == null) instance = new Manager(); return instance; } public void doSomething() { } } // Cannot create instance => Manager() is private // Manager manager = new Manager(); Manager manager = Manager.getInstace(); Manager.getInstace().doSomething();