mercredi 2 septembre 2015

Pattern to use for class data referenced by multiple child classes of Form1, only changeable by Form1

I am not sure what the best pattern is to apply here.

I have several classes acting as containers to SQL tabular data, called TestSpecSheet.vb.

User selections on the main form determine which records are fed to this data object, which is then referenced by multiple child objects:

Form1.vb

Public Class Form1
     TestUnits() as TestUnit   '<--these need to read the sql data, and each instance generates a report using the data values.

     Public testSpecs = New TestSpecSheet

     Private Sub deviceComboBox_SelectedIndexChanged(sender As Object, e As EventArgs) Handles deviceComboBox.SelectedIndexChanged
          FillTestSpecSheet(deviceComboBox.Text)

          For Each unit In TestUnits
               unit.SetTestSpecSheet(Me.testSpecs)
          Next
    End Sub

    Private Sub FillTestSpecSheet(deviceSelection As String)
         Dim dt = 'query to fill datatable with sql records
         testSpecs.ParseSpecs(dt) 
    End Sub



End Class

TestUnit.vb

 Public Class TestUnit

     Dim TestSpecSheet As TestSpecSheet

     Public Sub SetTestSpecSheet(specSheet As TestSpecSheet)
          DoSomethingWithSpecs()
     EndSub

     Private Sub DoSomethingWithSpecs()

     End Sub
 End Class

What is the best way to lend this data to the child classes so they (TestUnits) cannot modify the properties of the TestSpecSheet they are referencing? (Form1 does need to be able to pass a DataTable and other objects to TestSpecSheet class.

I hope this makes sense.

Thank you in advance.

Aucun commentaire:

Enregistrer un commentaire