public interface ISpellbook
public class RealSpellbook : ISpellbook
private string spellName;
public RealSpellbook(string spellName)
this.spellName = spellName;
Console.WriteLine($"Loading spell: {spellName}");
Console.WriteLine($"Casting spell: {spellName}");
public class SpellbookProxy : ISpellbook
private RealSpellbook realSpellbook;
private string spellName;
private int spellManaCost;
public SpellbookProxy(string spellName, int spellManaCost, int wizardMana)
this.spellName = spellName;
this.spellManaCost = spellManaCost;
this.wizardMana = wizardMana;
if (wizardMana >= spellManaCost)
if (realSpellbook == null)
realSpellbook = new RealSpellbook(spellName);
realSpellbook.CastSpell();
Console.WriteLine($"Not enough mana to cast {spellName}. Mana required: {spellManaCost}, Mana available: {wizardMana}");
static void Main(string[] args)
ISpellbook fireballSpell = new SpellbookProxy("Fireball", 30, wizardMana);
ISpellbook lightningSpell = new SpellbookProxy("Lightning Bolt", 60, wizardMana);
fireballSpell.CastSpell();
lightningSpell.CastSpell();