drawable class がありButton
ます。そのテクスチャを内部に保存して非表示にする必要があります。
class Button {
private:
Texture idle, hovered, clicked;
public:
void draw_self(Window&, Position) const;
};
void App::draw() {
button.draw_self(window, position);
}
...または、ある種のプロキシを覚えて、「より賢い」抽象化によって使用される魂のないゲッターを提供する方が賢明ですか?
class Button {
private:
std::string idle_tag, hovered_tag, clicked_tag;
public:
std::string const& get_texture_tag() const; // returns one of its tags
};
class Drawer {
private:
std::map<std::string, Texture> textures;
public:
void draw(std::string const&, Position) const;
};
void App::draw() {
drawer.draw(button.get_texture_tag(), position);
}
最初のアプローチButton
は、描画サブモジュールを認識しながら、完全に構成されたオブジェクトとして表現しているようです。2 番目の設計では、このような結合がなくなり、(おそらく) 並列化が容易になります。ただし、これButton
はばかげた DTO のように見え、あまり便利ではないインターフェースを提供します (提供されている例では違いが目立ちませんが、実際の例は苦痛です)。
通常はどちらの決定が好まれますか?またその理由は? 私が気付かなかった可能性のある問題 (またはその他の解決策) はありますか?