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

The C# Shorthand getters and setters

They don’t allow you to specify encapsulating behavior. What they do is allow you to specify that this is a Property in the public interface of your class, as opposed to a field. The difference here is that in Java, getters and setters are simply methods that follow a certain convention (getXXX, setXXX). In C#, … Read more

tech