I know that everything we do in programming can be described as design pattern(even abstract method has design pattern called template method)
public class Guicer extends AbstractModule {
private static Injector injector = Guice.createInjector(new Guicer());
public static void setInjector(Injector injector) {
Guicer.injector = injector;
}
public static <T> T getInstance(Class<T> c) {
return injector.getInstance(c);
}
@Override
protected void configure() {
}
}
What design patterns are used in this code? Id like to call that class GuiceStateHolder, but im not sure about it.
Well, I’d call this bit:
a write-only global variable.
And here:
you replace an instance method with a global function. So you’ve basically got a global variable, which anyone can write, but you can only call the one method on it. Since injector has more in its interface, it is possibly some kind of restricted façade.
But they are more idioms than a pattern – a pattern would also describe what it is trying to achieve in terms of desired behaviour, whereas an idiom is how you go about doing something in code.
Unless it is a pattern which has a very strong connection to a single idiom, then it is impossible to reverse-engineer patterns from code.