Linked Questions

14 votes
10 answers
9k views

Possible Duplicate: Why do we need private variables? I know that it's best practice to stay safe, and that we should always prevent others from directly accessing a class' properties. I hear this ...
Sal Rahman's user avatar
  • 1,544
13 votes
9 answers
4k views

Isn't scope just a way to organize classes, preventing outside code from accessing certain things you don't want accessed? More specifically, is there any functional gain to having public, protected, ...
Qix - MONICA WAS MISTREATED's user avatar
6 votes
6 answers
2k views

While I've never used a language that had built-in variable privacy, a book I'm reading by Douglas Crockford explains a way to create privacy in JavaScript, however it doesn't make sense to me so. The ...
J.Todd's user avatar
  • 3,833
17 votes
2 answers
65k views

In school, I've been told many times to stop using public for my variables. I haven't asked why yet. This question: Are Java's public fields just a tragic historical design flaw at this point? ...
Saturn's user avatar
  • 3,937
8 votes
2 answers
13k views

I'm watching a C++ tutorial video. It is talking about variables inside classes and assert that variables should be marked private. It explains that if I want to use them publicly, I should do it ...
Kendra Kaye Coffey's user avatar
0 votes
2 answers
1k views

Member variables of a class are typically hidden from the outside word (i.e., the other classes), with private access control modifier. Access to the member variables are provided via public ...
vqtuyen's user avatar
  • 15
0 votes
2 answers
249 views

Watchpoints and data break points make it possible to watch the changes of a value in memory in many languages. Much of the justification I have seen for getters and setters and private variables ...
calben's user avatar
  • 611
202 votes
14 answers
142k views

Getters and setters are often criticized as being not proper OO. On the other hand, most OO code I've seen has extensive getters and setters. When are getters and setters justified? Do you try to ...
-8 votes
3 answers
5k views

I had a very large ArrayList in Java, and I often need to check if it contains a particular value. This has proven very slow. Then I discovered that you can use a data structure based on a Hash. ...
Saturn's user avatar
  • 3,937
-2 votes
4 answers
270 views

So a 'fundamental' OOP principle is being able to control the access to various methods and fields from other parts of the program by making them public or private. The reason is so that you cannot ...
user1345541's user avatar
2 votes
1 answer
270 views

Is it fair to say that it is good practice to default everything to private up when defining a class? For example, for my public interface I would set my class something like this: class foo { ...
Asynch_'s user avatar
  • 43
1 vote
1 answer
121 views

At the new client, we had a discussion regarding access modifiers for classes, methods, members etc. One opinion was to keep things as private as possible, only allowing for protected (internal, ...
Konrad Viltersten's user avatar
1 vote
2 answers
247 views

I am doing a final project in a C++ class writing a very simple usenet-like client/server. I figure that since it's usenet-like I'll have a NewsGroup class and an Article class, I'm now working on my ...
evading's user avatar
  • 181