R
Rob Meade
Hi all,
Ok - I guess this one will eventually still end up as a "personal choice"
kinda answer, but I thought I'd run it passed the wealth of knowledge and
experience that's in this group.
Typically when I'm writing my classes I'll have a series of properties which
I set to be read only, I'll then, if I need to write some methods for
setting the values of the class level variables exposed in the readonly
properties.
I appreciate I could remove the word "ReadOnly" and use the "Set" method of
the property but I've always felt that it would be better to have something
explicit for setting the values so that another developer in our team would
be fully aware when they are setting these values...
For example
' class variable
Private _name As String
' properties
Public ReadOnly Property Name() As String
Get
Return _name
End Get
End Property
' methods
Public Sub SetName(ByVal value As String)
' set variable
_name = value
End Sub
Obviously in the above example I could just as easily use the property to
set the value instead of writing a separate method as its only doing very
simple things and with no big consequences.
I would be interested to know from others whether or not you do anything
similar or just use the properties to both get and set values.
Typically my classes themselves set the values, but every now and then they
will be the need for something else to set them, hence the sub being public
etc...
Any info appreciated.
Regards
Rob
Ok - I guess this one will eventually still end up as a "personal choice"
kinda answer, but I thought I'd run it passed the wealth of knowledge and
experience that's in this group.
Typically when I'm writing my classes I'll have a series of properties which
I set to be read only, I'll then, if I need to write some methods for
setting the values of the class level variables exposed in the readonly
properties.
I appreciate I could remove the word "ReadOnly" and use the "Set" method of
the property but I've always felt that it would be better to have something
explicit for setting the values so that another developer in our team would
be fully aware when they are setting these values...
For example
' class variable
Private _name As String
' properties
Public ReadOnly Property Name() As String
Get
Return _name
End Get
End Property
' methods
Public Sub SetName(ByVal value As String)
' set variable
_name = value
End Sub
Obviously in the above example I could just as easily use the property to
set the value instead of writing a separate method as its only doing very
simple things and with no big consequences.
I would be interested to know from others whether or not you do anything
similar or just use the properties to both get and set values.
Typically my classes themselves set the values, but every now and then they
will be the need for something else to set them, hence the sub being public
etc...
Any info appreciated.
Regards
Rob