0

This question already has an answer here:

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 hinges on the getters and setters being clear places in which break points can be set.

If watchpoints and data breakpoints make the break points on getters and setters a moot point, should I be using private members in my code anymore if I trust the other programmers on my team?

marked as duplicate by gnat, Community Jul 21 '15 at 16:01

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

4

I assume you mean "get rid of accessors and make private members public"... well, from a design point of view, a getter/setter is not doing much more than a public variable anyway, just with more layers.

Now, a good class design would not even begin to consider exposing a variable at all, it instead adds methods that apply to the internal state of the object (said state being expressed in terms of one or more variables) to perform logical operations on the object.

So really, getters and setters are a smell and should be removed. If you think of a class as a bundle of variables then you're not thinking right anyway, fix that first.

Once fixed, you find you'll have no getters or setters anyway and all variables will be private. Then you can put your breakpoints on the methods that operate on the class.

0

Getters and setters have nothing to do with breakpoints, although they may be helpful in this regard.

They are designed to allow the client to obtain and change the private data members of a class, while encapsulating what the class actually does to the data behind closed doors.

Not the answer you're looking for? Browse other questions tagged or ask your own question.