开发者

Handling Data Hierarchies in code

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 e开发者_开发问答ars

Thanks


I think I m going along the lines of having a collection allowed children types

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜