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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:19:33+00:00 2026-06-17T11:19:33+00:00

I am doing a large project for the first time. I have lots of

  • 0

I am doing a large project for the first time. I have lots of classes and some of them have public variables, some have private variables with setter and getter methods and same have both types.

I decided to rewrite this code to use primarily only one type. But I don’t know which I should use (variables which are used only for methods in the same object are always private and are not subject of this question).

I know the theory what public and private means, but what is used in the real world and why?

  • 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-17T11:19:35+00:00Added an answer on June 17, 2026 at 11:19 am

    private data members are generally considered good because they provide encapsulation.

    Providing getters and setters for them breaks that encapsulation, but it’s still better than public data members because there’s only once access point to that data.

    You’ll notice this during debugging. If it’s private, you know you can only modify the variable inside the class. If it’s public, you’ll have to search the whole code-base for where it might be modified.

    As much as possible, ban getters/setters and make properties private. This follows the principle of information hiding – you shouldn’t care about what properties a class has. It should be self-contained. Of course, in practice this isn’t feasible, and if it is, a design that follows this will be more cluttered and harder to maintain than one that doesn’t.

    This is of course a rule of thumb – for example, I’d just use a struct (equivalent with a class with public access) for, say, a simple point class:

    struct Point2D
    {
       double x;
       double y;
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm building a fairly large website in Django, and it's my first time doing
I'm currently doing some optimization work on a large web project. I'm already doing
I am doing some extremely large array processing. I do a global declaration of:
I'm doing some processing on some very large video files (often up to 16MP),
I am doing some testing for a very large website, created many different developers.
I'm working on my first Rails project, and I have the following model relationship:
I'm beginning to start on my first large project. It will be a program
I have access to a large C++ project, full of files and with a
I have a C# project in VS 2008, that is being rebuilt every time
So, I'm in the midst of my first major project with Angular. I have

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.