Skip to content

Classes

Sxtanna edited this page Jul 9, 2020 · 3 revisions

Classes are structures able to hold state and define functions.

Syntax

class 'name'{(property declarations)}{::['super types']} {
  (properties and functions)
}

  1. class
  • All classes start with the class keyword.
  1. name
  • Class names must follow UpperCamelCase naming standards.
  1. property declarations
  • Classes support declaring properties that need to be passed. (sort of like a constructor)
  1. super types
  • Classes can "extend" traits, copying all properties and functions from the trait into this class.
  1. properties and functions
  • Classes can hold any number of properties and functions, this is also where implementations of trait members would be.

Examples

trait Being(val name: Txt)

class Human(val age: Int)::[Being] {
  fun sayMyName {
    push "My name is $name"
  }

  fun sayMyAge {
    push "My age is $age"
  }
}

val sxtanna = Human { name: "Sxtanna", age: 21 }
sxtanna.sayMyName() // prints "My name is Sxtanna" to console.
sxtanna.sayMyAge()  // prints "My age is 21" to console.


Clone this wiki locally