💎 CRYSTAL GEM DIFFICULTY: Adept Structural

The Decorator: The Enchantment Wrapper

Attaching additional responsibilities to an object dynamically.

✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Decorator
ARCANUM SCHOOL: Transmutation // Enhancements
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// CRYSTAL PATTERN //
abstract class Relic
  abstract def inspect : String
  abstract def value : Int32
end

class Amulet < Relic
  def inspect : String
    "A simple brass amulet"
  end

  def value : Int32
    10
  end
end

abstract class RelicDecorator < Relic
  @relic : Relic

  def initialize(@relic : Relic)
  end
end

class GlowingEnchantment < RelicDecorator
  def inspect : String
    @relic.inspect + ", glowing with an eerie light"
  end

  def value : Int32
    @relic.value + 50
  end
end

class FloatingEnchantment < RelicDecorator
  def inspect : String
    @relic.inspect + ", floating slightly off the ground"
  end

  def value : Int32
    @relic.value + 100
  end
end

my_amulet = Amulet.new
puts "#{my_amulet.inspect} | Value: #{my_amulet.value}"

glowing_amulet = GlowingEnchantment.new(my_amulet)
puts "#{glowing_amulet.inspect} | Value: #{glowing_amulet.value}"

uber_amulet = FloatingEnchantment.new(glowing_amulet)
puts "#{uber_amulet.inspect} | Value: #{uber_amulet.value}"

Rather than forging infinite variations of magical items, the Decorator weaves volatile enchantments around a base Relic at runtime. Glowing, Floating, or Cursed modifiers wrap the object, stacking their magical effects elegantly.

Runic Tags: #structural #decorator #crystal #enchantment