Skip to main content
Version: 🚧 Alpha 🚧

Classes and Objects

GAML 2026 introduces the class and object keywords, bringing full object-oriented programming support beyond species. Classes allow you to define pure data/logic types that are not agents — they have no reflex, no schedule, and no population. They are simply structured values with attributes and methods.

Key concepts

  • A class is a blueprint for creating objects (instances). Declared with class ClassName { ... }.
  • An object is a value created by calling the class constructor: ClassName(attr: value, ...).
  • Classes can have attributes (like species variables) and actions (like species actions, but on objects).
  • Classes support inheritance with parent: ClassName.
  • Classes can be virtual (abstract) with virtual: true — they cannot be instantiated directly.
  • Objects can be stored in any GAML variable, passed as arguments, stored in lists, and used as map keys.

Step-by-Step overview

  • Class Definition and Instantiation — Declare a class, create objects with the constructor syntax ClassName(attr: value), store objects in variables and lists.
  • Attributes and Actions — Read and write attributes (dot notation: obj.attr <- value), call actions (obj.action()), chained calls, comparing objects, passing objects as arguments.
  • Inheritance — Extend a class with parent:, override actions, call parent implementation with super.action(), multi-level inheritance, runtime type testing with is.
  • Virtual Classes — Declare virtual (abstract) classes and virtual (abstract) actions, polymorphism, partial abstract classes, concrete implementations.
  • Advanced Features — Objects as agent attributes, passing objects between agents, objects in species, objects as map keys, object equality.

When to use Classes vs Species

FeatureClassSpecies
Is an agent?NoYes
Has reflex/actions/behaviors?No (methods are plain actions)Yes
Has a population?No (no count or lifecycle)Yes (count, init, lifecycle)
Can be an agent attribute?YesNo (species attributes are values)
Used for?Pure data types, structures, utilitiesSimulated entities in the world

See also