Over the years, I have followed the “best practice” of always using a property get and let/set combination rather than just declaring a public variable. But, over the last few months I’ve started questioning this dictum.
Now, before people start jumping up and down, I am aware of the many very, very good reasons why one should use properties rather than public variables. This comment is *limited* to the case where the property provides unrestricted access to the underlying value.
For those who want a clarification of what I am writing about, in a class module, one could have either
Public R As Single
Dim xR As Single
Public Property Get R() As Single
R = xR
Public Property Let R(uR As Single)
xR = uR
As far as a consumer of this class goes, the code would be identical irrespective of which of the above methods the developer of the class used.
One could argue that at some point, the developer may want to enforce a check on R (e.g., enforce that R > 0). Or one might want to provide a property that is read-only or write-once-read-many or one of many other scenarios where a property Get / Let would be required. But, until that happens, what’s the difference whether the class developer uses an unrestricted property or a public variable?