#include <string>
#include <map>
#include <iostream>

class Whatever {
public:
    // контракт
    virtual void foo() = 0;
};

class WhateverFactory {
public:
    typedef Whatever* (*WhateverCtor)();

    static void registerClass(const std::string &name, WhateverCtor ctor) {
        if ( m_plugins.find(name) == m_plugins.end() ) {
            m_plugins[name] = ctor;
        }
    }

    static bool isRegistered(const std::string &cls) {
        return m_plugins.find(cls) != m_plugins.end();
    }

    static Whatever* createInstanceOf(const std::string &name) {
        std::map<std::string, WhateverCtor>::iterator ctor;
        if ( (ctor = m_plugins.find(name)) != m_plugins.end() ) {
            return ctor->second();
        } else {
            return NULL;
        }
    }

private:
    WhateverFactory() {}

    static std::map<std::string, WhateverCtor> m_plugins;
};

std::map<std::string, WhateverFactory::WhateverCtor> WhateverFactory::m_plugins;

class HelloWorld : public Whatever {
public:
    HelloWorld() : m_message("Hello, World!") {}

    void foo() {
        std::cout << m_message << std::endl;
    }

    static HelloWorld* create() {
        return new HelloWorld;
    }

private:
    std::string m_message;
};

void load() {
    WhateverFactory::registerClass("HelloWorld", reinterpret_cast<WhateverFactory::WhateverCtor>(HelloWorld::create));
}

int main() {
    load();
    Whatever *w = WhateverFactory::createInstanceOf("HelloWorld");
    if ( w ) {
        w->foo();
    }

    return 0;
}