The Proxy Ward
Providing a surrogate or placeholder to control access to another object.
✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Proxy
ARCANUM SCHOOL: Abjuration // Gatekeeping
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// CSHARP PATTERN //
using System;
namespace EnterpriseEvocation
{
public interface IForbiddenTome
{
void ReadSecrets();
}
public class RealForbiddenTome : IForbiddenTome
{
public void ReadSecrets() => Console.WriteLine("Revealing sanity-shattering cosmic truths...");
}
public class TomeProxy : IForbiddenTome
{
private RealForbiddenTome _realTome;
private readonly int _userClearanceLevel;
public TomeProxy(int clearance)
{
_userClearanceLevel = clearance;
}
public void ReadSecrets()
{
if (_userClearanceLevel < 5)
{
Console.WriteLine("Access Denied: Insufficient arcane clearance.");
return;
}
if (_realTome == null)
{
Console.WriteLine("Materializing the Real Tome from the astral plane...");
_realTome = new RealForbiddenTome();
}
_realTome.ReadSecrets();
}
}
}
The Proxy pattern erects an Abjuration Ward around expensive or dangerous enterprise assets. It ensures that only those with sufficient arcane clearance may instantiate and invoke the true underlying entity.
Runic Tags:
#structural
#proxy
#access-control
#csharp