Question Style: Data Only Class?

VentureFree

Well-known member
Joined
Jan 9, 2008
Messages
54
Programming Experience
5-10
I've got a number of classes that I'm building based on existing databases. What I'm thinking of doing is creating some other classes that essentially do nothing but mirror the data columns. Basically no behavior, but lots of attributes.

In effect I'd have something like this:
VB.NET:
' Represents raw data for a given employee
' Note that this is a simplification of the actual data for brevity here
Public Class EmpRawData
    ' Create some basic, empty data.
    ' This data will be set explicitly by the user later
    Public Sub New()
        Me.PayrollNumber = 0
        Me.FirstName = ""
        Me.LastName = ""
    End Sub

    ' Pretend all of these are properties, rather than public variables
    ' I just did it this way to save space here
    Public PayrollNumber As Long
    Public FirstName As String
    Public LastName As String
End Class

Public Class Employee
    ' Make sure that the raw data isn't Nothing
    Public Sub New()
        Me._objRawData = New EmpRawData()
    End Sub
    ' Create a new employee with the given raw data
    Public Sub New(ByVal RawData As EmpRawData)
        Me._objRawData = RawData
    End Sub

    ' This is the raw data for this employee
    Private _objRawData As EmpRawData

    ' The payroll number of this employee
    Public ReadOnly Property PayrollNumber() As Long
        Get
            Return Me._objRawData.PayrollNumber
        End Get
    End Property
    ' The first name of this employee
    Public ReadOnly Property FirstName() As String
        Get
            Return Me._objRawData.FirstName
        End Get
    End Property
    ' The last name of this employee
    Public ReadOnly Property LastName() As String
        Get
            Return Me._objRawData.LastName
        End Get
    End Property
End Class
The main reason that I want to do it this way is just to simplify the constructors. Note the second constructor for Employee. The actual table itself contains upwards of 30 columns (it's frankly not very well designed, but I'm stuck with it), and I didn't want to have to make the properties writable or create constructors with 30 different arguments.

Is there a compelling reason not to do it this way?
 
Top Bottom