🟨 JAVASCRIPT PATTERN DIFFICULTY: Adept Structural

The Ward Proxy

Provide a surrogate or placeholder for another object to control access to it.

✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Proxy
ARCANUM SCHOOL: Abjuration // Warding
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// JAVASCRIPT IDIOMATIC PATTERN //
class VaultOfSecrets {
  open() { console.log("Vault opens, revealing arcane texts."); }
}

class WardedVaultProxy {
  constructor(password) {
    this.vault = new VaultOfSecrets();
    this.password = password;
  }

  open(attempt) {
    if (attempt === this.password) {
      this.vault.open();
    } else {
      console.log("Access Denied! The ward retaliates!");
    }
  }
}

const protectedVault = new WardedVaultProxy("Elbereth");
protectedVault.open("Mellon"); // Fails
protectedVault.open("Elbereth"); // Succeeds

The Ward Proxy

A true vault of secrets is never left exposed. A Proxy acts as the magical ward, intercepting all attempts to access the vault and only yielding to those with the proper credentials.

Runic Tags: #protection #access #proxies