Created
January 31, 2012 13:20
-
-
Save purplefox/1710437 to your computer and use it in GitHub Desktop.
Singleton or static
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
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