programming unknown conditions
-
I am just wondering if there is a pattern for programming conditions which are not known by the programmer at programming time; i.e. the conditions are set by the user. For example, the user may define a set IF conditions, and corresponding actions. If the IFs were finite, that would be easy. However, the user has a variable set of conditions/rules. A good example of this is a ERP-purchasing module application. The routing of a purchase order depends on approval level. The levels of approval are determined by the company policy. There could be any number of approval levels. In other word IF condition 1... then action 1 IF condition 2... then action 2 .. IF Condition n.... then action n but N is unknown at programming time. So I can't use the the typical if-else block. Any suggestions on how to handle this.
-
I am just wondering if there is a pattern for programming conditions which are not known by the programmer at programming time; i.e. the conditions are set by the user. For example, the user may define a set IF conditions, and corresponding actions. If the IFs were finite, that would be easy. However, the user has a variable set of conditions/rules. A good example of this is a ERP-purchasing module application. The routing of a purchase order depends on approval level. The levels of approval are determined by the company policy. There could be any number of approval levels. In other word IF condition 1... then action 1 IF condition 2... then action 2 .. IF Condition n.... then action n but N is unknown at programming time. So I can't use the the typical if-else block. Any suggestions on how to handle this.
Is this the sort of thing you mean? User Defined Dynamic Workflows in Workflow Foundation 4?[^] I'm almost certain that I've seen an article posted here about creating 1 to n dynamic workflows - I'll leave you to search for it. I would also think it possibel to do this by giving the users a blotter on which they can describe a workflow which is stored in a database. You then create forms based on the steps they have stored. That was off the top of my head so feel free to poke hole sin it. The idea, not my head...
"If you think it's expensive to hire a professional to do the job, wait until you hire an amateur." Red Adair. nils illegitimus carborundum me, me, me
-
I am just wondering if there is a pattern for programming conditions which are not known by the programmer at programming time; i.e. the conditions are set by the user. For example, the user may define a set IF conditions, and corresponding actions. If the IFs were finite, that would be easy. However, the user has a variable set of conditions/rules. A good example of this is a ERP-purchasing module application. The routing of a purchase order depends on approval level. The levels of approval are determined by the company policy. There could be any number of approval levels. In other word IF condition 1... then action 1 IF condition 2... then action 2 .. IF Condition n.... then action n but N is unknown at programming time. So I can't use the the typical if-else block. Any suggestions on how to handle this.
If I understood correctly you may use "not" !. I mean may be you shouldn't check all possibilities for user input. For example instead of checking this string userInput; //Got this from user input sould be "c" if(userInput == "a") {} else if(userInput == "b") {} else if(userInput == "c") {//Correct} You can use if(userInput == "c") {//Correct} else {}
-
I am just wondering if there is a pattern for programming conditions which are not known by the programmer at programming time; i.e. the conditions are set by the user. For example, the user may define a set IF conditions, and corresponding actions. If the IFs were finite, that would be easy. However, the user has a variable set of conditions/rules. A good example of this is a ERP-purchasing module application. The routing of a purchase order depends on approval level. The levels of approval are determined by the company policy. There could be any number of approval levels. In other word IF condition 1... then action 1 IF condition 2... then action 2 .. IF Condition n.... then action n but N is unknown at programming time. So I can't use the the typical if-else block. Any suggestions on how to handle this.
I find myself wondering how this question could possibly reflect a real-world scenario. The fact that there are "any number of approval levels" does not justify an assumption that the possible conditions are "infinite:" there is probably a fixed number of maximum approvals possible, or required. And, probably, a certain minimum of approvals required to even process the order. That the set of all possible permutations of approvals would require a unique action for each permutation: also seems a dubious assumption. And, isn't there some "hierarchy" involved here: a decision by upper-management to cancel/void/dis-approve takes precedence over other lower-level decision makers, which means you can deduce the action required without consideration of certain other levels ? In the real world, "hierarchy" also "kicks-in," in financial transactions, dependent upon customer credit, and $ize of order, as well as customer history, or internal (or external credit agency) rating. My guess is there is a finite, and well-defined, set of actions to be taken based on approvals of purchase order. So, present an interface with CheckBoxes: logical analysis of which are Checked then can be mapped to a list of appropriate actions. Or, present a TreeView with CheckBoxes, where you handle "hierarchy" by activating, or de-activting, sub-nodes, depending on whether "parent" nodes are checked. Then iterate the TreeView (recursively), and generate a list of actions based on all Checked Nodes.
"The first principle is that you must not fool yourself, and you are the easiest person to fool." Richard Feynman
-
I am just wondering if there is a pattern for programming conditions which are not known by the programmer at programming time; i.e. the conditions are set by the user. For example, the user may define a set IF conditions, and corresponding actions. If the IFs were finite, that would be easy. However, the user has a variable set of conditions/rules. A good example of this is a ERP-purchasing module application. The routing of a purchase order depends on approval level. The levels of approval are determined by the company policy. There could be any number of approval levels. In other word IF condition 1... then action 1 IF condition 2... then action 2 .. IF Condition n.... then action n but N is unknown at programming time. So I can't use the the typical if-else block. Any suggestions on how to handle this.
The answer to this depends on how flexible the user input and required response is supposed to be. It can go from simply holding a list of allowed values to embedding a scripting engine. To give any useful guidance we'll need to know more about what the user is expecting to be able to enter as conditions and actions.
-
I am just wondering if there is a pattern for programming conditions which are not known by the programmer at programming time; i.e. the conditions are set by the user. For example, the user may define a set IF conditions, and corresponding actions. If the IFs were finite, that would be easy. However, the user has a variable set of conditions/rules. A good example of this is a ERP-purchasing module application. The routing of a purchase order depends on approval level. The levels of approval are determined by the company policy. There could be any number of approval levels. In other word IF condition 1... then action 1 IF condition 2... then action 2 .. IF Condition n.... then action n but N is unknown at programming time. So I can't use the the typical if-else block. Any suggestions on how to handle this.
SilimSayo wrote:
I am just wondering if there is a pattern for programming conditions which are not known by the programmer at programming time; i.e. the conditions are set by the user.
That is not specific enough. There are a number of ways of dealing with that of which the specifics matter which way to implement it.
SilimSayo wrote:
For example, the user may define a set IF conditions, and corresponding actions
As expressed that requires an interpreter idiom (which is a pattern.)
SilimSayo wrote:
but N is unknown at programming time. So I can't use the the typical if-else block.
That of course has nothing to do with the problem as you expressed it. If you have defined conditions/actions and ALL the user does is pick from that set then the solution is trivial - use a set with an appropriate definition block. This is a very, very simple form of interpreter. However that doesn't solve it if the conditions/actions themselves are user defined.
-
I am just wondering if there is a pattern for programming conditions which are not known by the programmer at programming time; i.e. the conditions are set by the user. For example, the user may define a set IF conditions, and corresponding actions. If the IFs were finite, that would be easy. However, the user has a variable set of conditions/rules. A good example of this is a ERP-purchasing module application. The routing of a purchase order depends on approval level. The levels of approval are determined by the company policy. There could be any number of approval levels. In other word IF condition 1... then action 1 IF condition 2... then action 2 .. IF Condition n.... then action n but N is unknown at programming time. So I can't use the the typical if-else block. Any suggestions on how to handle this.
I would consider a collection of Func, Action pairs. then simply foreach the collection and if the Func returns true invoke the Action. building the collection is another matter and would really depend on what conditions you want the user to be able to define
Pedis ex oris Quidquid latine dictum sit, altum sonatur