tags:

views:

111

answers:

2

Hello, I'm trying to create a menu system that allows you to go backward and forward while returning the final selected data to the calling method.

Take for example a orderFood() method displays a menu of choices of types of food that can be ordered. If someone selects seafood a seafood() method would run and query what types of seafood is availble to order then display it

if the user selects fishsticks, fishsticks would be returned to the method that called order food. Likewise, this menu system would allow the user to go back to the previous menu.

I'm thinking (Using C#) I'd have to use reflection and unsafe code (pointers) to get this sort of effect but I am positive that there is a simpler way to do this. Any suggestions?

Thanks, Michael

A: 

You could easily do what you are describing without unsafe code provided you know at compile time, by making it data driven. Instead of thinking of menus as routines that do these things, think of menus as a class of objects that does these things. Ommm.

Even if you don't know everything at compile time (say you need to read the options from a file) you could still do it by building the nest of objects which represent your menus at run time, based on the contents of the file.

MarkusQ
+1  A: 

Instead of thinking about the menus as a stack, try thinking of them like a tree.

If you do this, it should be fairly easy to "walk" up and down the tree as you need to implement your stack approach.

This would be fairly easy to read from a file or database (very easy from XML, in particular), and also shouldn't be too tough to walk up and down.

There isn't really anything in this that should require unsafe code or reflection - it can all be done with standard collections in C#.

Reed Copsey