Classes (imiterere)
Kin supports a first-slice object-oriented model with classes, instances, methods, visibility, and single inheritance.
Sample programs live in the language repo under examples/oop/.
Keywords
| Keyword | Role |
|---|---|
imiterere | Declare a class (bound as a constant) |
tegura | Constructor |
rema | Create an instance |
_ | Current instance (only inside tegura / methods) |
rusange | Public field or method |
bwite | Private field or method |
ikomoka | Single inheritance (Child ikomoka Parent) |
Declare and construct
imiterere Umuntu {
tegura(izina, imyaka) {
rusange _.izina = izina
rusange _.imyaka = imyaka
}
rusange porogaramu_ntoya kwibwira() {
tangaza_amakuru("Nitwa ", _.izina, ", mfite imyaka ", _.imyaka)
}
rusange porogaramu_ntoya izina_ryose() {
tanga _.izina
}
}
reka keza = rema Umuntu("Keza", 20)
keza.kwibwira()
tangaza_amakuru(keza.izina_ryose())Field rules
- Fields exist only after a visibility-prefixed assignment in
tegura:rusange _.name = exprorbwite _.name = expr. - Later, methods update existing fields with
_.name = expr(no modifier). - You cannot invent new fields outside
tegura.
Methods
- Every class method needs
rusangeorbwitebeforeporogaramu_ntoya. - Accessing
instance.methodreturns a bound method β the receiver (_) is kept if you store and call later. - Field names take precedence over methods on the same name (avoid reusing a field name as a method name).
- Freestanding
porogaramu_ntoyafunctions (including nested helpers) do not inherit private access, even when called from a method.
reka f = keza.kwibwira
f()Visibility
rusangemembers are readable, writable, and callable from anywhere.bwitemembers are only visible inside methods /teguraof the class that declared them.- Public methods may wrap private helpers.
Inheritance
imiterere Umwarimu ikomoka Umuntu {
rusange porogaramu_ntoya kwibwira() {
tangaza_amakuru("Ndi umwarimu, nitwa ", _.izina)
}
}
reka m = rema Umwarimu("Keza", 28)- Single parent only (
ikomoka). - Method lookup starts on the instanceβs class and walks parents upward.
- A child with no
tegurainherits the parent constructor. - A child
tegurafully replaces the parent constructor (no automatic parent call).
Types with ubwoko
ubwoko is a prefix operator that yields a type value (used for identity checks). When printed it shows a name such as umubare.
tangaza_amakuru(ubwoko keza == Umuntu) # nibyo
tangaza_amakuru(ubwoko 5 == ubwoko 10) # nibyo
tangaza_amakuru(ubwoko 5 == ubwoko "5") # sibyoubwokoof an instance is the class value (exact match; no ancestor walk).- User functions and builtins share one function type value.
- Parenthesized form
ubwoko(x)still works. - The same keyword declares structural aliases:
ubwoko Id = ijambo | umubare.
Class names as annotations
After imiterere Umuntu { β¦ }, you can annotate bindings with the exact class:
reka keza: Umuntu = rema Umuntu("Keza", 20)
# Child is NOT assignable to the parent type annotation
# reka x: Umuntu = rema Umwarimu("K", 28) # type errorMethods and constructors may also use typed parameters and return types (umubare, ijambo, class names, β¦).
Plain objects vs classes
| Object literal | imiterere class | |
|---|---|---|
| Value kind | ubwoko_imiterere | instance of a named class |
| Shape | Ad-hoc keys | Fields from tegura + methods |
| Type check | Structural ubwoko alias or ubwoko_imiterere | Exact class annotation |
Object literals ({ izina: "K" }) remain quick bags of values.
imiterere is a named shape with fixed fields and methods.