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 58343
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T17:49:59+00:00 2026-05-10T17:49:59+00:00

Is it ever appropriate to abandon the getMyValue() and setMyValue() pattern of getters and

  • 0

Is it ever appropriate to abandon the ‘getMyValue()’ and ‘setMyValue()’ pattern of getters and setters if alternative function names make the API more obvious?

For example, imagine I have this class in C++:

 public class SomeClass { private:     bool mIsVisible;  public:     void draw();     void erase(); } 

I could add functions to get/set ‘mIsVisible’ like this:

 bool getVisible() { return mIsVisible; };

void setVisible(bool visible) { if (!mIsVisible && visible) { draw(); } else if (mIsVisible && !visible) { erase(); }

mIsVisible = visible; 

}

However, it would be equally possible to use the following methods instead:

 bool isVisible() { return mIsVisible; };  void show() {      if (!mIsVisible) {         mIsVisible = true;         draw();     } }  void hide() {     if (mIsVisible) {         mIsVisible = false;         erase();     } } 

In brief, is it better to have a single 'setVisible(bool)' method, or a pair of 'show()' and 'hide()' methods? Is there a convention, or is it purely a subjective thing?

  • 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. 2026-05-10T17:50:00+00:00Added an answer on May 10, 2026 at 5:50 pm

    Have a read of the article ‘Tell, Don’t Ask‘ over at the Pragmatic Programmers web site and I think you’ll see that the second example is the way to go.

    Basically, you shouldn’t be spreading the logic out through your code which is implied with your first example, namely:

    1. get current visibility value,
    2. make decision based on value,
    3. update object.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it ever appropriate to put functionality other than basic setters and getters in
Is it ever appropriate for a component to throw a FileNotFound exception that doesn't
It seems like it's more appropriate to use a meta redirect: <meta http-equiv=refresh content=0;url=$new_url
The best XML reading and writing API I've ever used is PHP's SimpleXMLElement .
Have you ever looked for a web API for certain data or functionality, only
The short form of this question: When, if ever, is it appropriate to use
Ever since I created this Rails 3.2.3 project to use MiniTest, I have been
Ever since ereg became depreciated, I began to use preg_match. Unfortunately in my code,
Ever since I discovered sockets, I've been using the nonblocking variants, since I didn't
Ever since I upgraded to Delphi 2009, I am having terrible experience with TFrame

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.