0

应用说明

我正在编写一个 GUI 驱动的应用程序,它将是 tileset/tilemap 编辑器。我决定使用命令设计模式来处理用户与 UI 组件的交互。

我的实现

我的应用程序类充当客户端/调用者,负责处理用户输入。我有指向两个 Receiver 类(TilesetEditor 和 TilemapEditor)的指针和指向存储当前使用的 Receiver 的地址的基类的指针。

客户端/调用者类:

class Application
{
private:
    TilesetEditor *m_tilesetEditor = nullptr;
    TilemapEditor *m_tilemapEditor = nullptr;
    Editor *m_activeEditor = nullptr;
    Command *m_command = nullptr;
};
void Application::handle_user_input(void)
{
    //user invokes new tilemap command
    {
        m_activeEditor = m_tilemapEditor;
        m_command = new CommandNewFile(m_activeEditor, filename);
        m_command->execute_command();
        delete m_command;
    }
}

有没有比在开始时简单地为两个编辑器分配内存然后只是更改基类指针指向的更好的方法来处理这种情况?另外应该如何处理/存储多个命令?

4

0 回答 0