I'm working on a JEE project, here is the situation:

I have an application that puts the maker/checker financial concept. The maker chooses an operation and can modify its values but the checker should approve these changes so they can be registered the problem is that some operation have certain conditions set that obliges to choose a certain checker these conditions can change depending on the maker. How can I take into consideration in my java code these conditions without knowing anything about them only that they're an input into the application?

Put simply how to code conditions made by an outsider user?


  • Operation: credit condition:

    if(card.equals("normal")) credit = 500 ;

    the maker may want to add another condition saying that the credit = 500 when we have a normal card and the user is under 20 years old. So the maker is changing the condition but he hasn't the access to the application however the application should take into consideration this change, does anyone have any idea how to implement this ?


1 Answer 1


This task can be viewed as 3 different subtasks. You need to define how the conditions are to be specified. You need some representation of the conditions. And you need to integrate it into the program.

How to specify conditions

Unless you users are able to program, it looks like you need a DSL (domain specific language). If developers write, or help domain experts write, the conditions and actions, here on referred to as 'rules' then you can probably do with a textual one. One option, if you use scripting languages, is to actually make the rules in that language with some syntactic sugar. But since you use Java, you will need to compile it. The language could for instance look something like this:

IF card = normal AND years < 20 THEN set credit = 500

The above snippet has a lot of context. If you can avoid being ambigous, then that can make the language alot simpler. For instance, whose 'years' are we talking about before? Well if the rules are being evaluated in the context of a card, then it is card owner. But if it is not clear the language may have to be more complicated, eg. 'years(owner(card))', and you might begin to scare normal users with the parantheses.

If it is not developers that writing the conditions, then you should strongly consider a graphical tool around your language. The graphical tool can constrain the options, to avoid spelling mistakes for instance, and guide users to available options.

Semantic model

Have some formal model of language. This could be an abstract syntax tree for expressions. And the root is a node with two children, a condition node, and an action node. Then to evaluate the rules for some context, you find the all the rules defined by the user, evaluate it using the abstract syntax tree, and it the condition is true, then run the action. You might also interprete the rules to handle conflicts. For example what happens if there is another rules that says 'if the card is normal and age of user less than 15 then set credit to 300'? Now both rules applies, but if that is not desirable you can inform the user. Beware, however if you language is too powerful, this can be undecidable, meaning you can't detect all such conflicts.

The above snippet might result in an abstract syntax tree like the following:

                 /                        \
               AND                     ACTIONS
        ______/   \______                 |
       /                 \              _SET_
    _ = _              _ < _           /     \
   /     \            /     \      credit    500
card    normal      age     20


You need to implement an interpreter or your semantic model. This will 'run' the model against the data you have. For example, use the current data in the system, to check the conditions described by the semantic model, then run the appropriate actions that updates the data.

For instance the pseudocode to process the setNode might look something like this:

onVisitSet(SetNode setNode, CardContext context) {
    if (setNode.assignType == CARD) {
        Account account = context.getAccountForCard();
    } else if (...)

Remember, though real banks don't just 'set' a balance.

  • Thank you for your comment , so if i get it the main idea here is that i need to set a DSL for the applciation users and then develop conditions generated depending on the DSL ?.
    – Elias
    Feb 28, 2017 at 16:43
  • Yes. You make a DSL for the user to write rules. Maybe the rules are stored in files. You application then reads the rules into some data structure. When your program needs to apply the rules it makes use of the data structure. Feb 28, 2017 at 16:50
  • what do you think about lambda expressions do you think they could present any help here ?
    – Elias
    Mar 1, 2017 at 9:25
  • Not sure what you mean, where do want to use the lambda expressions? You could certainly use lambda expressions in the implementation of the interpreter. Mar 3, 2017 at 23:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.