I am currently working on a game based on SFML and written in C++. For the HUD of the game I have a HUD class with a lot of different variables and methods. Basically most of the variables have a set and get method. We are talking about 14 variables currently and I am sure this will increase.
Example excerpts:
sf::Text m_AmmoText;
sf::Text m_ScoreText;
sf::Text getAmmoText();
sf::Text getScoreText();
void setAmmoText(sf::String text);
void setScore(sf::String text);
Questions
Optimize context is performance vs. code mantainability
1. Prototyp or Inheritance?
I searched the web and found the prototype pattern or the inheritance of classes as the most useful ones to apply. Since I never use both I am quite unsure which solution will have a positive impact on the code and performance. I am aware that with these few classes the performance impact is hardly measurable. It is more for practice and to get it right from the beginning. I started to re-write the code to apply inheritance but thought it might be better to ask the experts first.
Here is an example of the classes. Implementation of methods accordingly to read or write the variable (skipped here).
class HUD{
protected:
sf::Text m_Text;
public:
getText();
setText();
}
class HudAmmo : public Hud {};
class HudScore : public Hud {};
So instead of hud.getAmmoText() I could use hudammo.getText(). I did not code the prototyping yet. But read a lot about its pros and cons on the internet. Suprisingly I could not find a clear direction since most examples I found were abstract. I tend to apply the prototyping pattern from what I understood so far mainly because of this post:
2. Alternative
Re-write the class and have only 1 set and get method which passes the context, e.g. hiscore or other solutions?