OO Design Question (VB.Net)


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: OO Design Question (VB.Net)

  1. #1
    Join Date
    Feb 2005
    Posts
    3

    OO Design Question (VB.Net)

    I have an application class, and a small class for a data item, that just holds about 10 variables and has a few basic functions that work on those variables.

    I need functionality to load data received from outside (e.g. an XML file, or a database row) into an instance of the data class, and I can't decide where that functionality should go. Should the external data format be hidden from the data class and the functionality for loading the XML/db data be in the application class, or should the data class usefully be able to load data passed to it in native XML/ADO RS/other format?

    What I have at the moment is an overloaded method on the data class that can receive different types of data, which it loads into itself, something like

    class Data

    Overloads Public Sub Load (XMLData as XMLDoc)

    ...

    Overloads public Sub Load (DBData as ADO.RecordSet)

    What's the 'correct' way to structure something like this?

    Thanks

  2. #2
    Join Date
    May 2004
    Location
    Texas
    Posts
    21
    You should have another intermediate class that handles the source formatting for you. Your application and data item classes should remain encapsulated for the specific task. This way if you want to add, substract, or modify a format protocol later you can edit the new class and not have to change code in the other two and recompile, debug, etc.... That is assuming that you mandate your new class to format input data to be have the same end result everytime so your data class never has to change to handle any new format. Your new class will take care of that for you.

  3. #3
    Join Date
    Feb 2005
    Posts
    3
    Ok, so in terms of the code structure, is this how I'd lay that out:

    class Application

    Sub GettingSomeData

    If (Data is from database) then
    Dim Foo as new DataClass = DataHandlerClass.LoadData(DataRow)

    If (Data is XML) then
    Dim Foo as new DataClass = DataHandlerClass.LoadData(XML)

    end sub

    end class


    class DataHandlerClass

    OverLoaded Sub LoadData(Data as RecordSEt)
    ... (Load Data from Recordset) ...
    Return DataClass
    OverLoaded Sub LoadData(Data as XML)
    ... (Load Data from Recordset) ...
    Return DataClass

    end class

    class DataClass

    ...

    end class

  4. #4
    Join Date
    May 2004
    Location
    Texas
    Posts
    21
    Yes. Now your formatting process is independent of your app and DataClass and "blackboxed". Much easier to update and maintain.


    If you truly wanted to make code updates easier yo could make each class an assembly and link them so after you go into production and needed to make updates to a specific class you would not have to recompile the whole app. If you app is fairly small and simple this approach would not achieve much benefit however.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center