Classes & OOP
Djazair implements fully featured Object-Oriented programming including classes, constructors, methods, and single inheritance.
Class Declaration
Declare classes, instantiate objects, and refer to properties inside methods via the self prefix:
class User
init(name, email)
self.name = name
self.email = email
end
describe()
return "${self.name} <${self.email}>"
end
end
let admin = new User("Riad", "riad@djazair.org")
print(admin.describe())
Inheritance
Inherit classes using the is keyword. Override parent functions and trigger parent constructors using the super namespace keyword:
class Staff is User
init(name, email, role)
super.init(name, email)
self.role = role
end
describe()
return "${super.describe()} [Role: ${self.role}]"
end
end
let mod = new Staff("Sara", "sara@djazair.org", "Moderator")
print(mod.describe())