0

If you have a class with just contents like:

Public Class bertha
    Private x As Integer
    ' more fields here ...

    Public Property xVal() As Integer
        Get
            Return x
        End Get
        Set(value As Integer)
            x = value
        End Set
    End Property
    ' more simple properties here
End Class

Is there any reason not to use

Public Class bertha
    Public x As Integer
    ' more fields here ...
End Class

Now, this is a question on class philosophy, not the easiest way to use x.

If the class's variables will not be validated, and will not be processed, what is the advantage(s) of using access only through properties, rather than just making the field(s) Public?

Brian Wren
  • 367
  • 5
  • 15
  • Possible duplicate of [Why use getters and setters?](http://stackoverflow.com/questions/1568091/why-use-getters-and-setters) – jaco0646 Mar 24 '16 at 23:24

1 Answers1

0

One advantage is that subclasses would be able to add validation and/or processing.

Scott Hunter
  • 48,888
  • 12
  • 60
  • 101
  • If this is only ever going to be used to hold a slate of values, is there any advantage to interfacing through properties? – Brian Wren Mar 24 '16 at 20:13
  • If you could guarantee that restriction, probably not. But you gain a lot of flexibility accessing through properties: http://stackoverflow.com/a/1568230/535275 – Scott Hunter Mar 24 '16 at 20:19