Skip to content

Instantly share code, notes, and snippets.

@philipschwarz
Created September 25, 2011 21:27
Show Gist options
  • Save philipschwarz/1241175 to your computer and use it in GitHub Desktop.
Save philipschwarz/1241175 to your computer and use it in GitHub Desktop.
Separating use from construction - Before
public class BusinessObject {
public void actionMethod() {
// Other things
Service myServiceObject = Service.getInstance();
myServiceObject.doService();
// Other things
}
}
class Service {
private Service(){
//any needed construction behavior
}
public static Service getInstance() {
return new Service();
}
public void doService() {
//implementation here
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment