Skip to content

Instantly share code, notes, and snippets.

@purplefox
Created January 31, 2012 13:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save purplefox/1710437 to your computer and use it in GitHub Desktop.
Save purplefox/1710437 to your computer and use it in GitHub Desktop.
Singleton or static
Singleton:
public class Vertx {
public static Vertx instance = new Vertx();
private Vertx() {
}
public void foo() {
}
public void bar() {
}
public void quux() {
}
}
Usage:
Vertx.instance.foo();
Vertx.instance.bar();
Vertx.instance.quux();
Static:
public class Vertx {
public static void foo() {
}
public static void bar() {
}
public static void quux() {
}
}
Usage:
Vertx.foo();
Vertx.bar();
Vertx.quux();
Which do you prefer? The static version is less verbose for the reader.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment