Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8909045
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T03:20:15+00:00 2026-06-15T03:20:15+00:00

It’s a newbie question. In my simple learning rock-scissors-paper game program I have single

  • 0

It’s a newbie question. In my simple learning rock-scissors-paper game program I have single game instance class. Game instace class has several private members like total turns count, wins count, tie count etc. These class members are used only in public game instance’s class method, which starting and processing a game. Should I create special private getters and setters methods for my class members following good code style? Does it better to work directly with class members in game processing method?

class GameInstance{
    unsigned int m_totalTurns;
    unsigned int m_wins;
    unsigned int m_loses;
    unsigned int m_ties;
    int getWins() const;               // is it a bad idea?  
    int getLoses() const;              // is it a bad idea?  
    int getTotalTurns() const;         // is it a bad idea?  
    int getTies() const;               // is it a bad idea?  

    // some setters-like incrementing  // is it a bad idea?
    // same private members functions  // is it a bad idea?    
    // ....                            // is it a bad idea?  

    void finishGame();

public:
    explicit GameInstance():m_totalTurns(0), m_wins(0), m_loses(0), m_ties(0){}; 
    void startGame();
};
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T03:20:16+00:00Added an answer on June 15, 2026 at 3:20 am

    You’d probably make the getters public or there is no point in having them.

    With regards to any getters or setters, they are part of the interface of the class. If you don’t want to externally allow getting these members directly or setting them, do not expose getters and setters.

    With yours, getters might be an idea, setters looks it might be a bad idea, if you would rather have addResult() which specifies a win, tie or loss and adds one to the relevant stat.

    As an alternative to individual getters you might have a “getGameStats()” which returns all 4 in one go.

    If you are asking about getters rather than giving public access (rather than not giving access at all), for classes that have methods you should normally make all your data members private and use getters and if necessary, setters. It is also easier to debug code that is using them as you can insert breakpoints to the point the variables are being accessed.

    In a “pure data” struct you can make members public. In fact in this case you might have a “GameStats” struct that you would return from a getGameStats() function. GameStats itself would just contain numbers and you could make these public. However the instance of GameStats within your class should be a private instance.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have just tried to save a simple *.rtf file with some websites and
I am doing a simple coin flipping experiment for class that involves flipping a
This could be a duplicate question, but I have no idea what search terms
I don't have much knowledge about the IPv6 protocol, so sorry if the question
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
I have a small JavaScript validation script that validates inputs based on Regex. I
I have this code to decode numeric html entities to the UTF8 equivalent character.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.