What design pattern is this?

I know that everything we do in programming can be described as a design template (even an abstract method has a design template called a 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? I'd like to call this class GuiceStateHolder, but I'm not sure about that.

+3
source share
3 answers

Well, I would call this bit:

private static Injector injector = Guice.createInjector(new Guicer());

public static void setInjector(Injector injector) {
    Guicer.injector = injector;
}

global variable with record.

And here:

public static <T> T getInstance(Class<T> c) {
    return injector.getInstance(c);
}

. , , , . , , - .

, - , , - , - .

, , .

+1

, , , (, Guice) factory (getInstance()).

+2

This snippet is not a catalog design template. Templates (with the exception of Singleton) typically present more complex relationships than setting a default mutable implementation.

+1
source

Source: https://habr.com/ru/post/1747003/


All Articles