开发者

Workflow like system to change code flow

开发者 https://www.devze.com 2023-01-29 09:12 出处:网络
I need advice regarding a req开发者_JAVA百科uirement in one of our project. What we are trying to achieve is that we want to control flow of methods calls from a text or XML file.

I need advice regarding a req开发者_JAVA百科uirement in one of our project. What we are trying to achieve is that we want to control flow of methods calls from a text or XML file.

For example:

string response = new Assembly1.Class1().DoStuff();
if (response == "OK")
{
  new Assembly1.Class2().DoStuff();
}
else if (response == "NOTOK")
{
  new Assembly2.Class1().DoStuff();
}

How can i represent above code in some format that can be altered by non-technical user to modify the sequence of function calls.


Fundamentally, you have to decide what you are trying to accomplish.

C# code contains a certain amount of complexity in it, but all that complexity is there because C# code is very flexible.

You have to decide how much flexibility you want to give your non-technical users. If you want to give them the same flexibility as C#, well, you might as well just have them program in C#.

Otherwise, the first step is going to be to invent a domain-specific language that describes the configuration that they are going to do. Before you do that, though, you might want to research if there are any existing domain specific languages that already do what you're describing.

The next step, having defined a domain specific language, is to parse and interpret that language. This is relatively complicated, and is usually the subject of a one-semester long course in college called Compilers. If you haven't taken a compilers course, there are books you can read. You may be able to skip a lot of steps by using a markup language like XML and a standard XML parsing library.


I think you may use reflection for this purpose or generating code on-fly from xml. There are a lot of samples here.


Factory design pattern may be of good help to you. With factory pattern you can assign the objects at runtime and let those object decide the flow of the process...

You should build different classes with a method say WorkFlow() (referenced in a interface). The method should be able to call other methods based on the need.

At the beginning of the process, you just read the XML file and create an object for the appropriate class and call the workflow method of that class, which will inturn execute the pre-determined sequence.

0

精彩评论

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

关注公众号