🎲 R HARUSPEX DIFFICULTY: Adept Structural

The Flyweight: Sharing the Data Points

Conserving memory by sharing intrinsic state across millions of omens.

✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Flyweight
ARCANUM SCHOOL: Divination // Memory Compression
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// R PATTERN //
library(R6)

# Flyweight
OmenType <- R6Class("OmenType",
  public = list(
    name = NULL,
    color = NULL,
    initialize = function(name, color) {
      self$name <- name
      self$color <- color
    },
    display = function(x, y) {
      paste("Omen", self$name, "at", x, y, "in color", self$color)
    }
  )
)

# Flyweight Factory
OmenFactory <- R6Class("OmenFactory",
  private = list(
    omen_types = list()
  ),
  public = list(
    get_omen_type = function(name, color) {
      key <- paste(name, color, sep="_")
      if (is.null(private$omen_types[[key]])) {
        private$omen_types[[key]] <- OmenType$new(name, color)
      }
      return(private$omen_types[[key]])
    }
  )
)

When simulating a trillion possible futures, memory limits the Data Haruspex. The Flyweight pattern compresses shared characteristics to avoid out-of-memory astral tears.

Runic Tags: #R6 #Divination #Structural #Flyweight