Are getters and setters poor design? Contradictory advice seen [duplicate]

This question already has answers here: Why use getters and setters/accessors? (41 answers) Closed 6 years ago. I’m currently working on a simple game in Java with several different modes. I’ve extended a main Game class to put the main logic within the other classes. Despite this, the main game class is still pretty hefty. … Read more

Why JSF calls getters multiple times

Let’s say I specify an outputText component like this: <h:outputText value=”#{ManagedBean.someProperty}”/> If I print a log message when the getter for someProperty is called and load the page, it is trivial to notice that the getter is being called more than once per request (twice or three times is what happened in my case): DEBUG … Read more

What is the best way to give a C# auto-property an initial value?

How do you give a C# auto-property an initial value? I either use the constructor, or revert to the old syntax. Using the Constructor: class Person { public Person() { Name = “Initial Name”; } public string Name { get; set; } } Using normal property syntax (with an initial value) private string name = … Read more

Why use getters and setters/accessors?

There are actually many good reasons to consider using accessors rather than directly exposing fields of a class – beyond just the argument of encapsulation and making future changes easier. Here are the some of the reasons I am aware of: Encapsulation of behavior associated with getting or setting the property – this allows additional functionality (like validation) … Read more