views:

275

answers:

4

Here is the structure of the data my object will need to expose (the data is NOT really stored in XML, it was just the easiest way to illustrate the layout):

<Department id="Accounting">
  <Employee id="1234">Joe Jones</Employee>
  <Employee id="5678">Steve Smith</Employee>
</Department>
<Department id="Marketing">
  <Employee id="3223">Kate Connors</Employee>
  <Employee id="3218">Noble Washington</Employee>
  <Employee id="3233">James Thomas</Employee>
</Department>

When I de-serialize the data, how should I expose it in terms of properties on my object? If it were just Department and EmployeeID, I think I'd use a dictionary. But I also need to associate the EmployeeName, too.

(I'm using VB.NET.)

+1  A: 
  • A department object
  • An employee object
  • An employeeCollection object. (optional, you can just use List(of Employee))

Mark them all as serializable, and then you can (de)serialize them to whatever format you like.

StingyJack
+6  A: 

A Department class (with ID and Name), which contains a collection of Employee (ID and Name as well) objects.

Anton Gogolev
+6  A: 
Class Department
   Public Id As Integer
   Public Employees As List(Of Employee)
End Class

Class Employee
   Public Id As Integer
   Public Name As String
End Class

Something like that (can't remember my VB syntax). Be sure to use Properties versus Public members...

Corbin March
+1 that, coupled with a generic collection of departments
DrJokepu
Id of Department should be declared "as String", minor point.
Khnle
+2  A: 
Public Class Employee

    Private _id As Integer
    Public Property EmployeeID() As Integer
        Get
            Return _id
        End Get
        Set(ByVal value As Integer)
            _id = value
        End Set
    End Property

    Private _name As String
    Public Property Name() As String
        Get
            Return _name
        End Get
        Set(ByVal value As String)
            _name = value
        End Set
    End Property


End Class

Public Class Department

    Private _department As String
    Public Property Department() As String
        Get
            Return _department
        End Get
        Set(ByVal value As String)
            _department = value
        End Set
    End Property

    Private _employees As List(Of Employee)
    Public Property Employees() As List(Of Employee)
        Get
            Return _employees
        End Get
        Set(ByVal value As List(Of Employee))
            _employees = value
        End Set
    End Property

End Class
Hath