samedi 23 avril 2016

How to name an interface which have create, save and restore metohds

Naming functions and classes is a difficult task for me, is there a foundation about this in the world ?

In a GUI program, this interface is used to create a concrete object of Window class, save and restore its state, hence the WindowManager could restore the whole GUI state in a loose coupling way.

class WhatName {
public:
    Window* create() = 0;
    void saveState(Window*, Stream&) = 0;
    void restoreState(Window*, Stream&) = 0;
};

class Window {
    ...
};

class FooWindow : public Window {
    ...
};

class BarWindow : public Window {
    ...
};

class WindowManager {
public:
    void registerWhat(const string& className, WhatName*);

    void saveState();
    void restoreState();
    ...

private:
    map<string, WhatName*> whats_;
};

void WindowManager::registerWhat(const string& className, WhatName* p)
{
    whats_[className] = p;
}

void WindowManager::restoreState()
{
    Stream is = readFromFile();

    for (;;)
    {
        string className;

        is >> className;

        Window* window = whats_[className]->create();
        whats_[className]->restoreState(window, is);
        ...
    }
}

So what do you think ? What name will be good ?

Aucun commentaire:

Enregistrer un commentaire