The answer differs for different languages.
In C++ it is a good idea to make attributes private and provide getter and setter methods because C++ provides const correctness - and setters cannot be called on a const object.
In C# which does not offer const correctness it may seem pointless to do other than simply offer all attributes up as public, as the moment there is a setter it can be called at any time anyway.
But what if, for example, the property is a container (List, for example). It might then be that you only want people to be able to manipulate the list but not set the list pointer to a new value - so you would define the property like this:
class Contrived
{
private List<Things> m_List = new List<Things>();
public List<Things> LIST{ get {return m_List;} }
};
Or maybe you only want people to be able to examine the list, but not add or remove things from it:
class Contrived
{
private List<Things> m_List = new List<Things>();
public IEnumerable<Things> LIST{ get {return m_List;} }
};
In that way we are staggering towards faking const correctness by use of interfaces, although IMO it's not as good as just having a const correct language. ;-) Indeed, in the last example we provide a list that cannot be modified but who's contents can be, so we could implement the property like this (assuming Things implements IUnmoddableThing):
class Contrived
{
private List<Things> m_List = new List<Things>();
public IEnumerable<IUnmoddableThing> LIST{
get
{
List<IUnmoddableThing> temp = new List<IUnmoddableThing>();
... copy m_List into temp ...
return temp;
} }
};
Clearly allowing us much more control than simply making the member attribute public. And that's before we get into a property hiding the fact that we actually, maybe ... oh, connect to a remote database, via a socket, carried by a bespoke military radio...
Once you realise that a setter can be denied use at compile time (in a const correct language) and that a getter/setter or get/set (depending on language) can do more than simply assign or return, they can be very powerful.
{ get; private set; }
in C#.{set; get;}
is new makes me feel young again :)