5014

Compose a Validation Pipeline

Extensibility
Medium
Pro
interface
list
composition
pipeline

Compose a Validation Pipeline

Finance keeps inventing rules for which amounts the payment journal should accept: this sprint it is "no negative amounts" and "nothing above the approval limit", next sprint a consultant will bolt on a country-specific rule you have never heard of. You refuse to grow yet another if-chain. Instead you build a pipeline: each rule is a small check object, callers register the checks they need in the order they need them, and the pipeline runs them in one of two modes — fail fast while a user is typing, or a full report for a batch import.

Requirements

1. The check contract

Keep the interface "Amount Check" exactly as the starter declares it — two procedures:

procedure GetName(): Text
procedure IsValid(Amount: Decimal): Boolean

The grading tests implement this interface with their own instrumented checks and feed them to your pipeline, so its name and signatures must not change.

2. The pipeline

Create a codeunit named "Validation Pipeline" with exactly these public procedures:

procedure Register(Check: Interface "Amount Check")
procedure RunShortCircuit(Amount: Decimal; var FailedName: Text): Boolean
procedure RunAggregate(Amount: Decimal; var FailedNames: List of [Text]): Boolean

Rules:

  • Register appends a check to the pipeline. Any number of checks can be registered on one pipeline instance, and registering the same check twice means it is evaluated twice.
The rest of the statement and 3 hints Unlock with Pro
ALBusiness Central 28.5
Pro
Pro problem

Solve it with Pro

You’re reading the opening of the statement. Pro unlocks the whole problem:

  • The full statement
  • Starter code in the browser editor
  • 17 grading tests, run on Business Central 28.5
  • 3 hints
  • The reference solution

Pro also opens all 92 Pro problems and lifts the daily limits on compile checks and submissions.

$10 / month
or $100 / year
Upgrade
This problem is part of Pro
Pro unlocks the full statement, tests, hints and solution. The code editor works on a computer.
Upgrade