Last active
August 20, 2020 05:33
-
-
Save kkdeok/9574e9102b88cb5edf3614e0da279fe4 to your computer and use it in GitHub Desktop.
Design Pattern
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Singleton { | |
// As soon as field is declared, instance is created in the memory. | |
// It prevents exceptional case like multiple instances are created | |
// by multi-thread. We don't need to use keywork 'synchronize' in | |
// getInstance(). We just can ignore this case. | |
private static Singleton instance = new Singleton(); | |
// private constructor | |
private Singleton() {} | |
public static Singleton getInstance() { | |
return instance; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment