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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T10:20:49+00:00 2026-05-30T10:20:49+00:00

I don’t really understand why it’s generally good practice to make member variables and

  • 0

I don’t really understand why it’s generally good practice to make member variables and member functions private.

Is it for the sake of preventing people from screwing with things/more of an organizational tool?

  • 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-05-30T10:20:51+00:00Added an answer on May 30, 2026 at 10:20 am

    Basically, yes, it’s to prevent people from screwing with things.

    Encapsulation (information hiding) is the term you’re looking for.

    By only publishing the bare minimum of information to the outside world, you’re free to change the internals as much as you want.

    For example, let’s say you implement your phone book as an array of entries and don’t hide that fact.

    Someone then comes along and writes code which searches or manipulates your array without going through your “normal” interface. That means that, when you want to start using a linked list or some other more efficient data structure, their code will break, because it’s used that information.

    And that’s your fault for publishing that information, not theirs for using it 🙂

    Classic examples are the setters and getters. You might think that you could just expose the temperature variable itself in a class so that a user could just do:

    Location here = new Location();
    int currTemp = here.temp;
    

    But, what if you wanted to later have it actually web-scrape information from the Bureau of Meteorology whenever you asked for the temperature. If you’d encapsulated the information in the first place, the caller would just be doing:

    int currTemp = here.getTemp();
    

    and you could change the implementation of that method as much as you want. The only thing you have to preserve is the API (function name, arguments, return type and so on).


    Interestingly, it’s not just in code. Certain large companies will pepper their documentation with phrases like:

    This technical information is for instructional purposes only and may change in future releases.

    That allows them to deliver what the customer wants (the extra information) but doesn’t lock them in to supporting it for all eternity.

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

Sidebar

Related Questions

Don't know why people do not practice AJAX implementation for authentication systems. Is it
Don't let below code scare you away . The question is really simple, only
Don't really know how to formulate the title, but it should be pretty obvious
I don't understand where the extra bits are coming from in this article about
Don't think that I'm mad, I understand how php works! That being said. I
I don't know: if this works. if it's a good idea. what it is
don't understand: in my controller: @json = User.all.to_gmaps4rails do |user| \Title\: \#{user.email}\ end in
Don't understand, if Data.Map is and [] is. I found this out while wondering
Don't know why I can't reply to people on here with only a small
Don't quite understand determinism in the context of concurrency and parallelism in Haskell. Some

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.