liveBook · Manning

Affected attribute

As explained in Building User-Friendly DSLs

An affected attribute is the attribute whose value is determined or changed by a business rule effect.

An affected attribute is referenced by an effect and receives the value determined or changed by a business rule. In an Increment Effect, the attribute reference identifies the numeric attribute being incremented. section 14.1.3

Implementation concerns include:

  • Initialize the affected attribute before applying increments; a discount attribute therefore starts at 0%. section 14.2.2
  • Require an initial value rather than a computed value when an increment effect references the attribute. section 14.2.2
  • Collect affected attributes by inspecting each rule consequence and deduplicating the referenced attributes. section 14.3.1

Accumulating a discount

Set `let discount = 0` before executing the business rules. Each applicable Increment Effect adds its operand to the referenced discount attribute, leaving the variable with the value determined by the rules. section 14.2.2

Listing 14.27 Determining attributes affected by a rule’s consequence
const affectedAttributesInConsequence =     #1
         (consequence) => {
    if (!isAstObject(consequence)) {    #2
        return []
    }
    const { settings } = consequence
    switch (consequence.concept) {
        case "Increment Effect":
             return referencedAttributesIn(      #3
                 settings["attribute reference"])
        default: {
            console.warn(`affectedAttributesInConsequence(..)
                  doesn't handle instances of the
                  concept "${consequence.concept}"    #4
                  - returning []`)
            return []        #5
        }
    }
}
module.exports.affectedAttributesInConsequence =
     affectedAttributesInConsequence

Inspect how a consequence exposes its referenced attributes, then follow the query that aggregates affected attributes across business rules. section 14.3.1

How Building User-Friendly DSLs covers it

How deep it goes
Explains references, initialization, constraints, and AST queries, but stops short of implementing effects beyond Increment Effect.
Examples
Uses a discount variable, Increment Effect projections, initial-value validation, and affected-attribute query listings.
What it assumes
Assumes familiarity with attributes, business rules, consequences, effects, and AST references while defining affected attributes in context.
What you can do after
Build affected-attribute queries and enforce initialization constraints for increment effects.
How it connects
Connects affected attributes to business rules, consequences, effects, Increment Effect, Attribute Reference, AST objects, and code generation.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Building User-Friendly DSLs. The section links point to the parts of the book it draws on.