Linked Questions

7
votes
6answers
3k views

Are Get-Set methods a violation of Encapsulation? [duplicate]

Possible Duplicate: When are Getters and Setters Justified In an Object oriented framework, one believes there must be strict encapsulation. Hence, internal variables are not to be exposed ...
3
votes
8answers
1k views

Is it a good programming practice to not use getters and setters in trivial parts of code? [duplicate]

Possible Duplicate: When are Getters and Setters Justified Is it a good programming practice to not use getters and setters in trivial parts of code?
4
votes
3answers
1k views

Is it bad practice to use public fields? [duplicate]

Possible Duplicate: When are Getters and Setters Justified Why are public and private accessors considered good practice? In my time as developer I learned that properties can be very ...
5
votes
3answers
720 views

How important is encapsulation? [duplicate]

As a student in programming, I learned that encapsulation is one of the most important principles of object-oriented programming. However, I only follow that principle when I feel like it suits my ...
4
votes
4answers
933 views

Why are public and private accessors considered good practice? [duplicate]

Possible Duplicate: When are Getters and Setters Justified Why exactly is having public and private accessors like these: private string foo; public string Foo { get { ...
0
votes
1answer
6k views

What is the benefit of using getters and setters on properties in C#? [duplicate]

Possible Duplicate: When are Getters and Setters Justified Why do we use get and set method in C#? And why do we use public and private method property? For example: public class Date { ...
0
votes
3answers
168 views

which style of member-access is preferable [duplicate]

the purpose of oop using classes is to encapsulate members from the outer space. i always read that accessing members should be done by methods. for example: template<typename T> class foo_1 { ...
92
votes
12answers
29k views

Why do we need private variables?

Why do we need private variables in classes? Every book on programming I've read says this is a private variable, this is how you define it but stops there. The wording of these explanations always ...
6
votes
11answers
2k views

What is the point of properties?

Here are some arguments for properties and my counter-arguments: Easier to use than writing getter and setter methods Getter and setter method pairs are a code smell. Making it easier to write ...
14
votes
4answers
3k views

If a variable has getter and setter, should it be public?

I am an about to graduate Computer Science student so probably this is a stupid question. If I have a class with a variable that is private and the class have getter and setter for that variable. Why ...
7
votes
11answers
728 views

Why do interfaces require methods over members?

...As this forces us to create getters and setters, which in practice are often totally extraneous? Is there any good language-design reason why interfaces in most (all?) languages do not allow member ...
5
votes
4answers
2k views

When or why should one use getters/setters for class properties instead of simply making them public properties?

I program primarily in ColdFusion but this is a general OOP question. Is there any benefit to using: getProp() { return prop; } setProp(val) { prop = val; } As opposed to simply obj = ...

15 30 50 per page