|
-
May 29th, 2005, 11:44 PM
#1
Thread Starter
Frenzied Member
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:
Interface IParseable
Sub Read(byref Reader as BinaryReader)
Sub Write(byRef Writer as BinaryWriter)
End Interface
VB Code:
Public Class DataChunk
Implements IParsable
Public Sub New(byRef Reader as BinaryReader)
Read(Reader)
End Sub
Private _Header as ChunkHeader
Public Sub Read(byRef Reader as BinaryReader)
_Header = New ChunkHeader(Reader)
'
End Sub
'Write sub here (but not really relevant)
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:
Public Class DataChunk
Implements IParsable
Public Sub New(byRef Reader as BinaryReader)
Read(Reader)
End Sub
Private _Header as ChunkHeader
Public Sub Read(byRef Reader as BinaryReader)
_Header = New ChunkHeader(Reader)
ParseData(Reader)
End Sub
Public Sub Write(byRef Writer as BinaryWriter)
_Header.Write(Writer)
RenderData(Writer)
End Sub
Public MustOverride Sub ParseData(byRef Reader as BinaryReader)
Public MustOverride Sub RenderData(byRef Writer as BinaryWriter)
Public MustOverride Function CanParse(DataChunkName as String)
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
-
May 30th, 2005, 01:46 PM
#2
Thread Starter
Frenzied Member
Re: Design Patterns...
I'm still completely clueless...
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
-
May 30th, 2005, 05:26 PM
#3
Thread Starter
Frenzied Member
Re: Design Patterns...
Well I came up with a partial solution:
I created another interface for (IDataChunk)
ParseData, RenderData, CanParse.
Now how should I enumerate the parsing classes?
I could use reflection to get a array of all the types that Implement IDataChunk, but speed is an issue in the project.
I could hard code the List of parsing classes into the application, but It just seems.... un-elegant. (if this is the BEST method for speed/maintenance, I will do it this way).
Any other suggestions?
Edit: Never Mind... I jumped the gun.
Last edited by <ABX; May 30th, 2005 at 05:32 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
-
May 30th, 2005, 06:42 PM
#4
Fanatic Member
Re: Design Patterns...
In pattern speak, sounds "Factory"-ish. I know the idea of a [possibly] long select case sounds inelegant, but it's often the way to go - and more of an abstraction than it might seem at first blush. Look here - might get you on your way (seem like you probably want the simple factory - not [necessarily] the abstract one).
-
May 31st, 2005, 03:58 PM
#5
Thread Starter
Frenzied Member
Re: Design Patterns...
I think I will need the abstract factory (the version I posted here was simplifed). Don't have time to implement it now, but thanks.
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|