W
Webster
Hello,
Just wondering what's better programming style; to use public variables in a
class or to use private/protected variables and then expose them via
properties?
For example:
--------------------------------
Public Class public_person
Public firstname As String
Public lastname As String
End Class
---------------------------------
Public Class property_person
Dim firstname As String
Dim lastname As String
Public Property first_name() As String
Get
Return Me.firstname
End Get
Set(ByVal Value As String)
Me.firstname = Value
End Set
End Property
Public Property last_name() As String
Get
Return Me.lastname
End Get
Set(ByVal Value As String)
Me.lastname = Value
End Set
End Property
End Class
Which of the two classes is "better"?
Just wondering what's better programming style; to use public variables in a
class or to use private/protected variables and then expose them via
properties?
For example:
--------------------------------
Public Class public_person
Public firstname As String
Public lastname As String
End Class
---------------------------------
Public Class property_person
Dim firstname As String
Dim lastname As String
Public Property first_name() As String
Get
Return Me.firstname
End Get
Set(ByVal Value As String)
Me.firstname = Value
End Set
End Property
Public Property last_name() As String
Get
Return Me.lastname
End Get
Set(ByVal Value As String)
Me.lastname = Value
End Set
End Property
End Class
Which of the two classes is "better"?