CS FundamentalsHardProduct-company placement

A rules engine must evaluate business rules such as (age > 18 AND country = 'IN') OR isVip from a small fixed grammar, using one class per grammar rule (And, Or, Comparison, Variable) and a method evaluate(context) on each. Which design pattern is this?

  1. A. Interpreter
  2. B. Chain of Responsibility
  3. C. Strategy
  4. D. Command

Correct answer: A. Interpreter

Interpreter represents each grammar rule as a class and evaluates a sentence by recursively evaluating its syntax tree, which is structured as a Composite. Chain of Responsibility passes a request along handlers, not through a parse tree.

More Software Engineering, Git and Cloud Basics questions

Exams that ask this topic