jeudi 25 août 2016

Which creational pattern best describes this code?

I am studying design patterns (no, this is not for school, but my own edification and self-improvement). A project that I have worked on has the following architecture for one of its components:

class ProductFactory {
    static AbstractProduct * getProduct() {
        #ifdef ANDROID
            return new AndroidProduct;
        #elif defined IOS
            return new IOSProduct;
        #endif
            return 0;
    }
};

I'm having a terrible time trying to classify this code according to my readings on Abstract Factory and Factory Method. For example, the creator class is concrete and only one kind of product is created (as opposed to the canonical window, scrollbar, etc.). But which product-by-platform is created is not deferred to sub-classes -- rather, different sub-classes are created by the one creator class.

So my question is very simple: what pattern does the above code most/best conform to, and why?

Much appreciated!

Aucun commentaire:

Enregistrer un commentaire