jeudi 29 septembre 2016

Is this an example of a factory or strategy?

Suppose the following class chooses at runtime among a given set of instantiated singleton objects resolved from a dependency injection container:

class myClass {

    private container;   // DI container

    function getMeAnObject(input) {
        switch(input) {
            case A: return this.container.get(singletonA);
            case B: return this.container.get(singletonB);
            // etc...
        }   
    }
}

In this example would myClass be an implementation of the Factory or Strategy implementation or neither? Why?

Aucun commentaire:

Enregistrer un commentaire