{"id":"6b093dc191bd8fbaf2a0c8c4","slug":"expense-approval-chain","title":"Expense approval chain","summary":"An expense travels through links – receipt check, team lead, manager, director – until someone approves or rejects it. Chain of Responsibility with pluggable links.","servedLang":"en","availableLangs":["pl","en"],"kind":"code","category":"pattern","status":"published","difficulty":"easy","topics":["chain-of-responsibility"],"techs":["typescript","javascript","python","dotnet","java","go"],"tags":["chain-of-responsibility","approval-workflow","behavioral","middleware"],"languages":[{"lang":"typescript","runner":"browser","starter":"interface Expense {\n  employee: string;\n  amount: number;\n  hasReceipt: boolean;\n}\n\n/** One link of the chain: handles the expense or passes it to the next handler. */\nabstract class ApprovalHandler {\n  private next: ApprovalHandler | null = null;\n\n  /** Links `handler` after this one and returns it, so links can be chained: a.setNext(b).setNext(c). */\n  setNext(handler: ApprovalHandler): ApprovalHandler {\n    // TODO\n    throw new Error('Not implemented');\n  }\n\n  /** Default behaviour: pass to the next handler; at the end of the chain → 'rejected: no approver'. */\n  handle(expense: Expense): string {\n    // TODO\n    throw new Error('Not implemented');\n  }\n}\n\n/** Expenses above 50 without a receipt → 'rejected by receipt-check'; anything else goes on. */\nclass ReceiptCheck extends ApprovalHandler {\n  handle(expense: Expense): string {\n    // TODO\n    throw new Error('Not implemented');\n  }\n}\n\n/** Approves expenses up to `limit` → 'approved by <name>'; bigger ones go on. */\nclass Approver extends ApprovalHandler {\n  constructor(\n    readonly name: string,\n    readonly limit: number,\n  ) {\n    super();\n  }\n\n  handle(expense: Expense): string {\n    // TODO\n    throw new Error('Not implemented');\n  }\n}\n\n/** receipt-check → team-lead (1 000) → manager (5 000) → director (20 000). */\nfunction defaultChain(): ApprovalHandler {\n  // TODO\n  throw new Error('Not implemented');\n}\n","testCount":8,"tests":"const expense = (amount, hasReceipt = true, employee = 'bob') => ({ employee, amount, hasReceipt });\n\ntest('a small expense is approved by the team lead', () => {\n  expect(defaultChain().handle(expense(300))).toBe('approved by team-lead');\n});\n\ntest('each approver handles amounts up to its limit', () => {\n  const chain = defaultChain();\n  expect(chain.handle(expense(1000))).toBe('approved by team-lead');\n  expect(chain.handle(expense(1001))).toBe('approved by manager');\n  expect(chain.handle(expense(5000))).toBe('approved by manager');\n  expect(chain.handle(expense(12000))).toBe('approved by director');\n});\n\ntest('an amount above every limit falls off the end of the chain', () => {\n  expect(defaultChain().handle(expense(25000))).toBe('rejected: no approver');\n  expect(new Approver('solo', 10).handle(expense(11))).toBe('rejected: no approver');\n});\n\ntest('the receipt check stops the chain early', () => {\n  const chain = defaultChain();\n  expect(chain.handle(expense(120, false))).toBe('rejected by receipt-check');\n  expect(chain.handle(expense(40, false))).toBe('approved by team-lead');\n});\n\ntest('setNext() returns the linked handler for fluent wiring', () => {\n  const a = new ReceiptCheck();\n  const b = new Approver('team-lead', 1000);\n  const c = new Approver('manager', 5000);\n  expect(a.setNext(b)).toBe(b);\n  b.setNext(c);\n  expect(a.handle(expense(4000))).toBe('approved by manager');\n});\n\ntest('a custom handler can be inserted without changing the others', () => {\n  class FraudCheck extends ApprovalHandler {\n    handle(e) {\n      if (e.employee === 'mallory') return 'rejected by fraud-check';\n      return super.handle(e);\n    }\n  }\n  const chain = new FraudCheck();\n  chain.setNext(new ReceiptCheck()).setNext(new Approver('team-lead', 1000));\n  expect(chain.handle(expense(10, true, 'mallory'))).toBe('rejected by fraud-check');\n  expect(chain.handle(expense(10, true, 'bob'))).toBe('approved by team-lead');\n});\n\ntest('the request stops at the first handler that takes it', () => {\n  const log = [];\n  class Recorder extends ApprovalHandler {\n    constructor(label) {\n      super();\n      this.label = label;\n    }\n    handle(e) {\n      log.push(this.label);\n      return super.handle(e);\n    }\n  }\n  const chain = new Recorder('first');\n  chain.setNext(new Approver('team-lead', 1000)).setNext(new Recorder('second')).setNext(new Approver('manager', 5000));\n  expect(chain.handle(expense(300))).toBe('approved by team-lead');\n  expect(log).toEqual(['first']);\n  expect(chain.handle(expense(3000))).toBe('approved by manager');\n  expect(log).toEqual(['first', 'first', 'second']);\n});\n\ntest('the order of links decides who handles the request', () => {\n  const chain = new Approver('manager', 5000);\n  chain.setNext(new Approver('team-lead', 1000));\n  expect(chain.handle(expense(300))).toBe('approved by manager');\n});\n"},{"lang":"javascript","runner":"browser","starter":"// Expense: { employee: string, amount: number, hasReceipt: boolean }\n\n/** One link of the chain: handles the expense or passes it to the next handler. */\nclass ApprovalHandler {\n  next = null;\n\n  /** Links `handler` after this one and returns it, so links can be chained: a.setNext(b).setNext(c). */\n  setNext(handler) {\n    // TODO\n    throw new Error('Not implemented');\n  }\n\n  /** Default behaviour: pass to the next handler; at the end of the chain → 'rejected: no approver'. */\n  handle(expense) {\n    // TODO\n    throw new Error('Not implemented');\n  }\n}\n\n/** Expenses above 50 without a receipt → 'rejected by receipt-check'; anything else goes on. */\nclass ReceiptCheck extends ApprovalHandler {\n  handle(expense) {\n    // TODO\n    throw new Error('Not implemented');\n  }\n}\n\n/** Approves expenses up to `limit` → 'approved by <name>'; bigger ones go on. */\nclass Approver extends ApprovalHandler {\n  constructor(name, limit) {\n    super();\n    this.name = name;\n    this.limit = limit;\n  }\n\n  handle(expense) {\n    // TODO\n    throw new Error('Not implemented');\n  }\n}\n\n/** receipt-check → team-lead (1 000) → manager (5 000) → director (20 000). */\nfunction defaultChain() {\n  // TODO\n  throw new Error('Not implemented');\n}\n","testCount":8,"tests":"const expense = (amount, hasReceipt = true, employee = 'bob') => ({ employee, amount, hasReceipt });\n\ntest('a small expense is approved by the team lead', () => {\n  expect(defaultChain().handle(expense(300))).toBe('approved by team-lead');\n});\n\ntest('each approver handles amounts up to its limit', () => {\n  const chain = defaultChain();\n  expect(chain.handle(expense(1000))).toBe('approved by team-lead');\n  expect(chain.handle(expense(1001))).toBe('approved by manager');\n  expect(chain.handle(expense(5000))).toBe('approved by manager');\n  expect(chain.handle(expense(12000))).toBe('approved by director');\n});\n\ntest('an amount above every limit falls off the end of the chain', () => {\n  expect(defaultChain().handle(expense(25000))).toBe('rejected: no approver');\n  expect(new Approver('solo', 10).handle(expense(11))).toBe('rejected: no approver');\n});\n\ntest('the receipt check stops the chain early', () => {\n  const chain = defaultChain();\n  expect(chain.handle(expense(120, false))).toBe('rejected by receipt-check');\n  expect(chain.handle(expense(40, false))).toBe('approved by team-lead');\n});\n\ntest('setNext() returns the linked handler for fluent wiring', () => {\n  const a = new ReceiptCheck();\n  const b = new Approver('team-lead', 1000);\n  const c = new Approver('manager', 5000);\n  expect(a.setNext(b)).toBe(b);\n  b.setNext(c);\n  expect(a.handle(expense(4000))).toBe('approved by manager');\n});\n\ntest('a custom handler can be inserted without changing the others', () => {\n  class FraudCheck extends ApprovalHandler {\n    handle(e) {\n      if (e.employee === 'mallory') return 'rejected by fraud-check';\n      return super.handle(e);\n    }\n  }\n  const chain = new FraudCheck();\n  chain.setNext(new ReceiptCheck()).setNext(new Approver('team-lead', 1000));\n  expect(chain.handle(expense(10, true, 'mallory'))).toBe('rejected by fraud-check');\n  expect(chain.handle(expense(10, true, 'bob'))).toBe('approved by team-lead');\n});\n\ntest('the request stops at the first handler that takes it', () => {\n  const log = [];\n  class Recorder extends ApprovalHandler {\n    constructor(label) {\n      super();\n      this.label = label;\n    }\n    handle(e) {\n      log.push(this.label);\n      return super.handle(e);\n    }\n  }\n  const chain = new Recorder('first');\n  chain.setNext(new Approver('team-lead', 1000)).setNext(new Recorder('second')).setNext(new Approver('manager', 5000));\n  expect(chain.handle(expense(300))).toBe('approved by team-lead');\n  expect(log).toEqual(['first']);\n  expect(chain.handle(expense(3000))).toBe('approved by manager');\n  expect(log).toEqual(['first', 'first', 'second']);\n});\n\ntest('the order of links decides who handles the request', () => {\n  const chain = new Approver('manager', 5000);\n  chain.setNext(new Approver('team-lead', 1000));\n  expect(chain.handle(expense(300))).toBe('approved by manager');\n});\n"},{"lang":"python","runner":"browser","starter":"from dataclasses import dataclass\n\n\n@dataclass(frozen=True)\nclass Expense:\n    employee: str\n    amount: float\n    has_receipt: bool = True\n\n\nclass ApprovalHandler:\n    \"\"\"One link of the chain: handles the expense or passes it to the next handler.\"\"\"\n\n    def __init__(self):\n        self._next = None\n\n    def set_next(self, handler: \"ApprovalHandler\") -> \"ApprovalHandler\":\n        \"\"\"Links `handler` after this one and returns it: a.set_next(b).set_next(c).\"\"\"\n        # TODO\n        raise NotImplementedError\n\n    def handle(self, expense: Expense) -> str:\n        \"\"\"Default behaviour: pass to the next handler; at the end of the chain → 'rejected: no approver'.\"\"\"\n        # TODO\n        raise NotImplementedError\n\n\nclass ReceiptCheck(ApprovalHandler):\n    \"\"\"Expenses above 50 without a receipt → 'rejected by receipt-check'; anything else goes on.\"\"\"\n\n    def handle(self, expense: Expense) -> str:\n        # TODO\n        raise NotImplementedError\n\n\nclass Approver(ApprovalHandler):\n    \"\"\"Approves expenses up to `limit` → 'approved by <name>'; bigger ones go on.\"\"\"\n\n    def __init__(self, name: str, limit: float):\n        super().__init__()\n        self.name = name\n        self.limit = limit\n\n    def handle(self, expense: Expense) -> str:\n        # TODO\n        raise NotImplementedError\n\n\ndef default_chain() -> ApprovalHandler:\n    \"\"\"receipt-check → team-lead (1 000) → manager (5 000) → director (20 000).\"\"\"\n    # TODO\n    raise NotImplementedError\n","testCount":8,"tests":"def check(got, want):\n    assert got == want, f\"expected {want!r}, got {got!r}\"\n\n\ndef test_a_small_expense_is_approved_by_the_team_lead():\n    check(default_chain().handle(Expense(\"bob\", 300)), \"approved by team-lead\")\n\n\ndef test_each_approver_handles_amounts_up_to_its_limit():\n    chain = default_chain()\n    check(chain.handle(Expense(\"bob\", 1000)), \"approved by team-lead\")\n    check(chain.handle(Expense(\"bob\", 1001)), \"approved by manager\")\n    check(chain.handle(Expense(\"bob\", 5000)), \"approved by manager\")\n    check(chain.handle(Expense(\"bob\", 12000)), \"approved by director\")\n\n\ndef test_an_amount_above_every_limit_falls_off_the_end_of_the_chain():\n    check(default_chain().handle(Expense(\"bob\", 25000)), \"rejected: no approver\")\n    check(Approver(\"solo\", 10).handle(Expense(\"bob\", 11)), \"rejected: no approver\")\n\n\ndef test_the_receipt_check_stops_the_chain_early():\n    chain = default_chain()\n    check(chain.handle(Expense(\"bob\", 120, has_receipt=False)), \"rejected by receipt-check\")\n    check(chain.handle(Expense(\"bob\", 40, has_receipt=False)), \"approved by team-lead\")\n\n\ndef test_set_next_returns_the_linked_handler_for_fluent_wiring():\n    a, b, c = ReceiptCheck(), Approver(\"team-lead\", 1000), Approver(\"manager\", 5000)\n    assert a.set_next(b) is b, \"set_next() must return the handler it linked\"\n    b.set_next(c)\n    check(a.handle(Expense(\"bob\", 4000)), \"approved by manager\")\n\n\ndef test_a_custom_handler_can_be_inserted_without_changing_the_others():\n    class FraudCheck(ApprovalHandler):\n        def handle(self, expense):\n            if expense.employee == \"mallory\":\n                return \"rejected by fraud-check\"\n            return super().handle(expense)\n\n    chain = FraudCheck()\n    chain.set_next(ReceiptCheck()).set_next(Approver(\"team-lead\", 1000))\n    check(chain.handle(Expense(\"mallory\", 10)), \"rejected by fraud-check\")\n    check(chain.handle(Expense(\"bob\", 10)), \"approved by team-lead\")\n\n\ndef test_the_request_stops_at_the_first_handler_that_takes_it():\n    log = []\n\n    class Recorder(ApprovalHandler):\n        def __init__(self, label):\n            super().__init__()\n            self.label = label\n\n        def handle(self, expense):\n            log.append(self.label)\n            return super().handle(expense)\n\n    chain = Recorder(\"first\")\n    chain.set_next(Approver(\"team-lead\", 1000)).set_next(Recorder(\"second\")).set_next(Approver(\"manager\", 5000))\n    check(chain.handle(Expense(\"bob\", 300)), \"approved by team-lead\")\n    check(log, [\"first\"])\n    check(chain.handle(Expense(\"bob\", 3000)), \"approved by manager\")\n    check(log, [\"first\", \"first\", \"second\"])\n\n\ndef test_the_order_of_links_decides_who_handles_the_request():\n    chain = Approver(\"manager\", 5000)\n    chain.set_next(Approver(\"team-lead\", 1000))\n    check(chain.handle(Expense(\"bob\", 300)), \"approved by manager\")\n"},{"lang":"csharp","runner":"judge0","starter":"using System;\n\npublic class Expense\n{\n    public Expense(string employee, decimal amount, bool hasReceipt = true)\n    {\n        Employee = employee;\n        Amount = amount;\n        HasReceipt = hasReceipt;\n    }\n\n    public string Employee { get; private set; }\n    public decimal Amount { get; private set; }\n    public bool HasReceipt { get; private set; }\n}\n\n/// <summary>One link of the chain: handles the expense or passes it to the next handler.</summary>\npublic abstract class ApprovalHandler\n{\n    private ApprovalHandler next;\n\n    /// <summary>Links handler after this one and returns it: a.SetNext(b).SetNext(c).</summary>\n    public ApprovalHandler SetNext(ApprovalHandler handler)\n    {\n        // TODO\n        throw new NotImplementedException();\n    }\n\n    /// <summary>Default behaviour: pass to the next handler; at the end of the chain → \"rejected: no approver\".</summary>\n    public virtual string Handle(Expense expense)\n    {\n        // TODO\n        throw new NotImplementedException();\n    }\n}\n\n/// <summary>Expenses above 50 without a receipt → \"rejected by receipt-check\"; anything else goes on.</summary>\npublic class ReceiptCheck : ApprovalHandler\n{\n    public override string Handle(Expense expense)\n    {\n        // TODO\n        throw new NotImplementedException();\n    }\n}\n\n/// <summary>Approves expenses up to the limit → \"approved by &lt;name&gt;\"; bigger ones go on.</summary>\npublic class Approver : ApprovalHandler\n{\n    public Approver(string name, decimal limit)\n    {\n        Name = name;\n        Limit = limit;\n    }\n\n    public string Name { get; private set; }\n    public decimal Limit { get; private set; }\n\n    public override string Handle(Expense expense)\n    {\n        // TODO\n        throw new NotImplementedException();\n    }\n}\n\npublic static class ExpenseApproval\n{\n    /// <summary>receipt-check → team-lead (1 000) → manager (5 000) → director (20 000).</summary>\n    public static ApprovalHandler DefaultChain()\n    {\n        // TODO\n        throw new NotImplementedException();\n    }\n}\n","testCount":8},{"lang":"java","runner":"judge0","starter":"class Expense {\n    private final String employee;\n    private final double amount;\n    private final boolean hasReceipt;\n\n    Expense(String employee, double amount, boolean hasReceipt) {\n        this.employee = employee;\n        this.amount = amount;\n        this.hasReceipt = hasReceipt;\n    }\n\n    Expense(String employee, double amount) { this(employee, amount, true); }\n\n    String getEmployee() { return employee; }\n    double getAmount() { return amount; }\n    boolean hasReceipt() { return hasReceipt; }\n}\n\n/** One link of the chain: handles the expense or passes it to the next handler. */\nabstract class ApprovalHandler {\n    private ApprovalHandler next;\n\n    /** Links handler after this one and returns it: a.setNext(b).setNext(c). */\n    ApprovalHandler setNext(ApprovalHandler handler) {\n        // TODO\n        throw new UnsupportedOperationException(\"Not implemented\");\n    }\n\n    /** Default behaviour: pass to the next handler; at the end of the chain → \"rejected: no approver\". */\n    String handle(Expense expense) {\n        // TODO\n        throw new UnsupportedOperationException(\"Not implemented\");\n    }\n}\n\n/** Expenses above 50 without a receipt → \"rejected by receipt-check\"; anything else goes on. */\nclass ReceiptCheck extends ApprovalHandler {\n    @Override\n    String handle(Expense expense) {\n        // TODO\n        throw new UnsupportedOperationException(\"Not implemented\");\n    }\n}\n\n/** Approves expenses up to the limit → \"approved by <name>\"; bigger ones go on. */\nclass Approver extends ApprovalHandler {\n    private final String name;\n    private final double limit;\n\n    Approver(String name, double limit) {\n        this.name = name;\n        this.limit = limit;\n    }\n\n    @Override\n    String handle(Expense expense) {\n        // TODO\n        throw new UnsupportedOperationException(\"Not implemented\");\n    }\n}\n\nclass ExpenseApproval {\n    /** receipt-check → team-lead (1 000) → manager (5 000) → director (20 000). */\n    static ApprovalHandler defaultChain() {\n        // TODO\n        throw new UnsupportedOperationException(\"Not implemented\");\n    }\n}\n","testCount":8},{"lang":"go","runner":"judge0","starter":"package main\n\n// Expense is a cost reported by an employee.\ntype Expense struct {\n\tEmployee   string\n\tAmount     float64\n\tHasReceipt bool\n}\n\n// Handler is one link of the approval chain.\ntype Handler interface {\n\tHandle(e Expense) string\n\tSetNext(next Handler) Handler\n}\n\n// Link is embedded by concrete handlers: it stores the next handler and passes requests on.\ntype Link struct {\n\tnext Handler\n}\n\n// SetNext links next after this handler and returns it: a.SetNext(b).SetNext(c).\nfunc (l *Link) SetNext(next Handler) Handler {\n\t// TODO\n\treturn nil\n}\n\n// PassOn sends the expense to the next handler; at the end of the chain it returns \"rejected: no approver\".\nfunc (l *Link) PassOn(e Expense) string {\n\t// TODO\n\treturn \"\"\n}\n\n// ReceiptCheck rejects expenses above 50 without a receipt (\"rejected by receipt-check\"); anything else goes on.\ntype ReceiptCheck struct {\n\tLink\n}\n\n// Handle implements Handler.\nfunc (r *ReceiptCheck) Handle(e Expense) string {\n\t// TODO\n\treturn \"\"\n}\n\n// Approver approves expenses up to Limit (\"approved by <Name>\"); bigger ones go on.\ntype Approver struct {\n\tLink\n\tName  string\n\tLimit float64\n}\n\n// NewApprover creates an approver with a name and a limit.\nfunc NewApprover(name string, limit float64) *Approver {\n\treturn &Approver{Name: name, Limit: limit}\n}\n\n// Handle implements Handler.\nfunc (a *Approver) Handle(e Expense) string {\n\t// TODO\n\treturn \"\"\n}\n\n// DefaultChain: receipt-check → team-lead (1 000) → manager (5 000) → director (20 000).\nfunc DefaultChain() Handler {\n\t// TODO\n\treturn &ReceiptCheck{}\n}\n","testCount":8}],"questionCount":null,"xp":10,"stats":{"attempts":0,"solves":0,"solutions":0,"comments":0},"solveRate":null,"publishedAt":"2026-11-27T08:22:25.083Z","requestedLang":"en","statement":{"type":"doc","content":[{"type":"paragraph","content":[{"type":"text","text":"In the company's expense app the amount decides who approves: a team lead up to 1,000, a manager up to 5,000, a director up to 20,000. Before that, every expense above 50 must have a receipt. The rules keep changing (finance wants a fraud check next), so instead of one huge "},{"type":"text","text":"if","marks":[{"type":"code"}]},{"type":"text","text":" we build a "},{"type":"text","text":"Chain of Responsibility","marks":[{"type":"bold"}]},{"type":"text","text":": every link either handles the expense or passes it on."}]},{"type":"heading","attrs":{"level":2,"id":"task"},"content":[{"type":"text","text":"Task"}]},{"type":"orderedList","attrs":{"start":1},"content":[{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"ApprovalHandler","marks":[{"type":"code"}]},{"type":"text","text":" (in Go – the embedded "},{"type":"text","text":"Link","marks":[{"type":"code"}]},{"type":"text","text":" struct):"}]},{"type":"bulletList","content":[{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"setNext(handler)","marks":[{"type":"code"}]},{"type":"text","text":" links the next handler and "},{"type":"text","text":"returns it","marks":[{"type":"bold"}]},{"type":"text","text":", so the chain can be built fluently: "},{"type":"text","text":"a.setNext(b).setNext(c)","marks":[{"type":"code"}]},{"type":"text","text":";"}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"the default "},{"type":"text","text":"handle(expense)","marks":[{"type":"code"}]},{"type":"text","text":" passes the expense on and, at the end of the chain, returns "},{"type":"text","text":"rejected: no approver","marks":[{"type":"code"}]},{"type":"text","text":"."}]}]}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"ReceiptCheck","marks":[{"type":"code"}]},{"type":"text","text":" – an expense above 50 without a receipt ends with "},{"type":"text","text":"rejected by receipt-check","marks":[{"type":"code"}]},{"type":"text","text":"; anything else goes on."}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"Approver(name, limit)","marks":[{"type":"code"}]},{"type":"text","text":" – approves an amount not greater than "},{"type":"text","text":"limit","marks":[{"type":"code"}]},{"type":"text","text":" ("},{"type":"text","text":"approved by <name>","marks":[{"type":"code"}]},{"type":"text","text":") and passes bigger ones on."}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"defaultChain()","marks":[{"type":"code"}]},{"type":"text","text":" – the chain "},{"type":"text","text":"receipt-check → team-lead (1,000) → manager (5,000) → director (20,000)","marks":[{"type":"code"}]},{"type":"text","text":"."}]}]}]},{"type":"table","content":[{"type":"tableRow","content":[{"type":"tableHeader","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Expense"}]}]},{"type":"tableHeader","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Result"}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"300, with a receipt"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"approved by team-lead","marks":[{"type":"code"}]}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"1,001, with a receipt"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"approved by manager","marks":[{"type":"code"}]}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"120, no receipt"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"rejected by receipt-check","marks":[{"type":"code"}]}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"25,000"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"rejected: no approver","marks":[{"type":"code"}]}]}]}]}]},{"type":"paragraph","content":[{"type":"text","text":"The tests add their own links (a fraud check and a recorder) – they must work without changing the existing classes. Names per language: "},{"type":"text","text":"set_next","marks":[{"type":"code"}]},{"type":"text","text":"/"},{"type":"text","text":"default_chain","marks":[{"type":"code"}]},{"type":"text","text":" (Python), "},{"type":"text","text":"SetNext","marks":[{"type":"code"}]},{"type":"text","text":"/"},{"type":"text","text":"ExpenseApproval.DefaultChain()","marks":[{"type":"code"}]},{"type":"text","text":" (C#), "},{"type":"text","text":"ExpenseApproval.defaultChain()","marks":[{"type":"code"}]},{"type":"text","text":" (Java), "},{"type":"text","text":"SetNext","marks":[{"type":"code"}]},{"type":"text","text":"/"},{"type":"text","text":"PassOn","marks":[{"type":"code"}]},{"type":"text","text":"/"},{"type":"text","text":"DefaultChain()","marks":[{"type":"code"}]},{"type":"text","text":" (Go)."}]},{"type":"callout","attrs":{"variant":"tip","title":"Seen it before?"},"content":[{"type":"paragraph","content":[{"type":"text","text":"This is how middleware pipelines work: ASP.NET Core ("},{"type":"text","text":"next()","marks":[{"type":"code"}]},{"type":"text","text":"), Express and Koa in Node.js, Servlet filters and Spring Security in Java, "},{"type":"text","text":"http.Handler","marks":[{"type":"code"}]},{"type":"text","text":" wrappers in Go."}]}]}]},"hints":[],"hintsCount":3,"quiz":null,"solutionNotes":null,"unlocked":false,"external":[],"articles":[{"id":"6b08bd3080884893657cc8fc","slug":"chain-of-responsibility","title":"Chain of Responsibility: pass it on until someone takes care of it"},{"id":"6b08bd3280884893657cc938","slug":"decorator","title":"Decorator – adding behaviour layer by layer"}],"topicsInfo":[{"slug":"chain-of-responsibility","title":"Chain of Responsibility","group":"behavioral","icon":"link"}],"author":{"id":"6b08bd2e80884893657cc8cf","name":"Redakcja Art of Devs","avatar":null,"handle":"redakcja","community":false},"capabilities":{"judge0":false,"aiReview":false},"createdAt":"2026-11-27T08:22:25.085Z","updatedAt":"2026-11-27T08:22:25.085Z"}