Skip to content

Instantly share code, notes, and snippets.

@kkdeok
Last active August 20, 2020 05:33
Show Gist options
  • Save kkdeok/9574e9102b88cb5edf3614e0da279fe4 to your computer and use it in GitHub Desktop.
Save kkdeok/9574e9102b88cb5edf3614e0da279fe4 to your computer and use it in GitHub Desktop.
Design Pattern
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