Wednesday, August 04, 2004

Use of properties within the class scope

By the theories of OO we should use the private member within the class but not the Property.

But properties can be used to validate a value before being assigned to the private variable.

My personal idea is, when validation is required, have a separate private method to do validation and call that method inside the property’s setter and else where.

i.e:

Private m_name As String


Public Property Name() As String
Get
Return m_name
End Get
Set(ByVal Value As String)
Dim validValue As Boolean
validValue = ValidateName(Value)
If validValue Then
m_name = Value
End If
End Set
End Property

Private Function ValidateName(ByVal p_name As String) As Boolean
If p_name.Length < validvalue =" ValidateName(p_name)" m_name =" p_name">
Or should we set the property in side SetName method?
What is the best practice to use in such situations?

Please send in your ideas