Decisions as Pure Functions (no side effects) - Gnorion/BizVR GitHub Wiki

Decisions as Pure Functions (no side effects)

It is possible to create a decision where all the decision tables are pure functions

Example of a Decision Using Functions and Methods

  • No assignment statements are used
  • The decision is entirely side-effect free
  • The output is specified as a function of the inputs
  • The value will be returned from that function
  • Functions can safely be executed in parallel
  • Evaluation starts at the output function and works backwards through the other function calls
  • The only named values are the inputs

image

The inputs x and y could be values, objects or collections

Function f(x,y) defined as a decision table:

image

Instead of referring to variable names in the conditions it makes further calls to two functions g(x) and h(y) that will return values.

Function g(x) defined as a decision table:

image

Function h(y) defined as a decision table:

image

Validation

The validator also works when decision tables are defined this way.

For example it identifies these missing rules in the various functions

MISSING RULES

  1. if y in(1..2) then result not specified in ruleset h(y) (RS202)
  2. if y<1 then result not specified in ruleset h(y) (RS202)
  3. if y>2 then result not specified in ruleset h(y) (RS202)
  4. if g(x)='g1' and h(y)='h2' then result not specified in ruleset f(x,y) (RS200)
  5. if g(x)='g2' and h(y)='h1' then result not specified in ruleset f(x,y) (RS200)",

Using Instance Methods

image