سؤال

data flow example

I have been trying to find a proper way to represent the above data flow (this is just a small case), and I'm not sure if I found a good way to do it. Our current implementation just evaluate all the previous data like: (if user.isMarried && user.age > 23 & ....), so is very hard to maintain.

Basically, what I need is a way to calculate the next step based on current input and previous conditions. I've been thinking about a finite state machine, but my main issue is that it will not only depend on the input, but previous data already answered.

It also came to my mind using something like a decision tree, but I can't represent it properly. Any light on the subject would be really appreciated.

Note: Check that the blank questions doesn't depend on the input, but on previous answers (married or not).

هل كانت مفيدة؟

المحلول

One solution is a state machine, because in a state machine even if you process one entry at a time, you are on a different state based on the previous set of actions. This is also especially useful if you have cycles. Actually, the flowchart diagram IS a state machine. Follow it with a pen, the box you are currently in is based on what happened before, the box in which you are going to get depends on the input AND on where you are coming from (i.e. what happened before).

The problem is managing the states and their transitions, which is hard to do in an imperative language.

Prolog has been suggested in comments, which can help a lot in your case, since it has been designed at least partially for handling complex rules. It's nice because it's efficient for this kind of task, can evaluate lots of rules very fast and you can reuse your rules. The downside is that, at least from my experience, it required quite a lot of brain rewiring to learn it if you're not used to the paradigm.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى softwareengineering.stackexchange
scroll top