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

How to write C++ getters and setters

There are two distinct forms of “properties” that turn up in the standard library, which I will categorise as “Identity oriented” and “Value oriented”. Which you choose depends on how the system should interact with Foo. Neither is “more correct”. Identity oriented Here we return a reference to the underlying X member, which allows both sides of the call site … Read more