Properties and Object Oriented Database Development with VB.NET 2005 - The class “Emp” rewritten with properties
(Page 2 of 4 )
Since I explained the “properties” in the previous section, we shall rewrite the class “emp” by adding properties to the fields as follows:
Public Class Emp
Private m_empno As String
Private m_ename As String
Private m_sal As Double
Private m_deptno As Integer
Public Property sal() As Double
Get
Return m_sal
End Get
Set(ByVal value As Double)
If value < 0 Then
Throw New Exception("Salary cannot be negative")
End If
m_sal = value
End Set
End Property
Public Property empno() As String
Get
Return m_empno
End Get
Set(ByVal value As String)
m_empno = value
End Set
End Property
Public Property ename() As String
Get
Return m_ename
End Get
Set(ByVal value As String)
m_ename = value
End Set
End Property
Public Property deptno() As Integer
Get
Return m_deptno
End Get
Set(ByVal value As Integer)
m_deptno = value
End Set
End Property
...
End Class
In the current case, I included validation for the property “sal” only. Based on the requirements, you may need to add a few more validations to a few more properties accordingly.
Next: Accessing the object properties from the form >>
More Visual Basic.NET Articles
More By Jagadish Chaterjee