Handling Data Hierarchies in code

Posted by Miau on Stack Overflow See other posts from Stack Overflow or by Miau
Published on 2010-05-05T16:17:37Z Indexed on 2010/05/17 19:30 UTC
Read the original article Hit count: 243

Filed under:
|

Hi there

So, say I have a string to parse with a given format that maps to a tree like data structure. The string is kinda similar to a folder path, and the structure is similar to a file structure, except its got some rules

so for something@cat1@otherSomething

you would get

 /something/cat1/otherSomething 

for something@cat2@otherSomething you would get

 /something/cat2/otherSomething

other examples

/OtherThing/cat1/otherSomething/Blah
/OtherThing/cat4/otherSomething

Where something, cat1, otherSomethign, etc are some sort of instances of ICategory

There are certain rules that control what subcategories are valid and which subcategories are not acceptable, at the moment I m considering a heavy Object hierachy, but I know this is not a flexible solution, I d prefer the categories to be a bit more general but again, since there are rules about what can go next I m not sure how to do this.

An example of a rule can be: OtherThing can only have subcategories cat1 and cat4 ( anything else is invalid)

An option would be to use some sort of convention based aproach to instantiate a particular class given a subsection of the string(like cat4) but it seems a bit too complex, I m all ears

Thanks

© Stack Overflow or respective owner

Related posts about c#

Related posts about conventions