开发者

Data-structure to hold large number of state machine information

I have a XML file and want to represent a complex finite state machine described in a XML file in a c# data-structure. What data structure can I use? Definition of one state is here. the state machine shows sync and async trans开发者_开发知识库itions and actions according to various async events.


You should probably start by taking a look at how the State Design Pattern could possibly help you.

You have two things that you need

If your state instances are pre-created.

  1. The internal representation of those states, which you can deserialize the XML into. This would be a series of classes which represent the XML structure.

  2. Since each state seems to have an ID and you use this ID to transition to the target state, you can store the state objects (these are from point 1) in a Dictionary where the key is the ID and the value is the state object. When you execute a transition, you just look-up the target state in the dictionary and get the instance from there.

If the state instances are to be created on demand

The dictionary will contain the meta-data for each state (this can be the XML or an optimized format that is hydrated from the original XML) then when a state transition is required, you look-up the state in the dictionary and dynamically instantiate the state from the meta-data associated with the state id.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜