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

  • Home
  • SEARCH
  • 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 497875
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T05:49:25+00:00 2026-05-13T05:49:25+00:00

I understand the differences between them (at least in C#). I know the effects

  • 0

I understand the differences between them (at least in C#). I know the effects they have on the elements to which they are assigned. What I don’t understand is why it is important to implement them – why not have everything Public?

The material I read on the subject usually goes on about how classes and methods shouldn’t have unnecessary access to others, but I’ve yet to come across an example of why/how that would be a bad thing. It seems like a security thing, but I’m the programmer; I create the methods and define what they will (or will not) do. Why would I spend all the effort to write a function which tried to change a variable it shouldn’t, or tried to read information in another class, if that would be bad?

I apologize if this is a dumb question. It’s just something I ran into on the first articles I ever read on OOP, and I’ve never felt like it really clicked.

  • 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-13T05:49:25+00:00Added an answer on May 13, 2026 at 5:49 am

    First, nothing in the language forces you to use access modifiers – you are free to make everything public in your class if you wish. However, there are some compelling reasons for using them. Here’s my perspective.

    1. Hiding the internals of how your class operates allows you to protect that class from unintended uses. While you may be the creator of the class, in many cases you will not be the only consumer – or even maintainer. Hiding internal state protects the class for people who may not understand its workings as well as you. Making everything public creates the temptation to “tweak” the internal state or internal behavior when the class isn’t acting the way you may want – rather than actually correcting the public interface of internal implementation. This is the road to ruin.

    2. Hiding internals helps to de-clutter the namespace, and allows tools like Intellisense to display only the relevant and meaningful methods/properties/fields. Don’t discount tools like Intellisense – they are a powerful means for developers to quickly identify what they can do with your class.

    3. Hiding internals allows you to structure an interface appropriate for the problem the class is solving. Exposing all of the internals (which often substantially outnumber the exposed interface) makes it hard to later understand what the class is trying to solve.

    4. Hiding internals allows you to focus your testing on the appropriate portion – the public interface. When all methods/properties of a class are public, the number of permutations you must potentially test increases significantly – since any particular call path becomes possible.

    5. Hiding internals helps you control (enforce) the call paths through your class. This makes it easier to ensure that your consumers understand what your class can be asked to do – and when. Typically, there are only a few paths through your code that are meaningful and useful. Allowing a consumer to take any path makes it more likely that they will not get meaningful results – and will interpret that as your code being buggy. Limiting how your consumers can use your class actually frees them to use it correctly.

    6. Hiding the internal implementation frees you to change it with the knowledge that it will not adversely impact consumers of your class – so long as your public interface remains unchanged. If you decide to use a dictionary rather than a list internally – no one should care. But if you made all the internals of your class available, someone could write code that depends on the fact that your internally use a list. Imagine having to change all of the consumers when you want to change such choices about your implementation. The golden rule is: consumers of a class should not care how the class does what it does.

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

Sidebar

Ask A Question

Stats

  • Questions 389k
  • Answers 389k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer libkdtree++ or kdtree May 15, 2026 at 12:43 am
  • Editorial Team
    Editorial Team added an answer You will need to use VS2008 to work with VS2008… May 15, 2026 at 12:43 am
  • Editorial Team
    Editorial Team added an answer MySQLi has procedural-style function calls that can handle prepared statements.… May 15, 2026 at 12:43 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.