Results 1 to 5 of 5

Thread: Design Patterns... [Resolved]

Threaded View

  1. #1

    Thread Starter
    Frenzied Member <ABX's Avatar
    Join Date
    Jul 2002
    Location
    Canada eh...
    Posts
    1,622

    Resolved Design Patterns... [Resolved]

    Lets say I have a Class Named DataChunk each data chunk class has a header, this header has some basic Information on what the DataChunk contains.

    Based on the name that Header Contains I need to figure out what Parsing class should be created and then add it to a collection

    This is a basic version of the class

    VB Code:
    1. Interface IParseable
    2.  
    3. Sub Read(byref Reader as BinaryReader)
    4. Sub Write(byRef Writer as BinaryWriter)
    5.  
    6. End Interface

    VB Code:
    1. Public Class DataChunk
    2.     Implements IParsable
    3.  
    4.     Public Sub New(byRef Reader as BinaryReader)
    5.          Read(Reader)
    6.     End Sub
    7.  
    8.     Private _Header as ChunkHeader
    9.  
    10.     Public Sub Read(byRef Reader as BinaryReader)
    11.         _Header = New ChunkHeader(Reader)
    12.        '
    13.     End Sub
    14.  
    15.     'Write sub here (but not really relevant)
    16.  
    17. End Class

    ChunkHeader also Implements IParseable.

    basicly There are many different types of dataChunk's, the Header's name property is what should be used to decide what class should be used to continue parsing.

    These data chunks need to be stored in a typed collection so I was thinking of Inheriting Declaring dataChunk as MustOverride...

    eg..

    VB Code:
    1. Public Class DataChunk
    2.     Implements IParsable
    3.  
    4.     Public Sub New(byRef Reader as BinaryReader)
    5.          Read(Reader)
    6.     End Sub
    7.  
    8.     Private _Header as ChunkHeader
    9.  
    10.     Public Sub Read(byRef Reader as BinaryReader)
    11.         _Header = New ChunkHeader(Reader)
    12.         ParseData(Reader)
    13.     End Sub
    14.  
    15.     Public Sub Write(byRef Writer as BinaryWriter)
    16.        _Header.Write(Writer)
    17.        RenderData(Writer)
    18.     End Sub
    19.  
    20.     Public MustOverride Sub ParseData(byRef Reader as BinaryReader)
    21.     Public MustOverride Sub RenderData(byRef Writer as BinaryWriter)
    22.     Public MustOverride Function CanParse(DataChunkName as String)
    23.  
    24. End Class

    but then how do I dynamicly create an instance of the proper class only knowing the DataChunkName
    Last edited by <ABX; May 31st, 2005 at 03:59 PM.
    Tips:
    • Google is your friend! Search before posting!
    • Name your thread appropriately... "I Need Help" doesn't cut it!
    • Always post your code!!!! We can't read your mind!!! (well, at least most of us!)
    • Allways Include the Name and Line of the Exception (if one is occuring!)
    • If it is relevant state the version of Visual Studio/.Net Framwork you are using (2002/2003/2005)


    If you think I was helpful, rate my post
    IRC Contact: Rizon/xous ChakraNET/xous Freenode/xous

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width