实现
Translation status: 简体中文 reader-locale proof. Term names and code fences follow the zh-Hans pack; supporting prose may still be English.
Declares that a type implements one or more 契约 contracts.
Aliases: implements
Syntax: 类 <name> 实现 <interface-list> <block>
Category#
type
Related#
Examples#
radix/corpus/implet/implet.fab (canonical · keyword)#
Declares that a type implements one or more 契约 contracts.
# =============================================================================
# 实现 — Declares that a type implements one or more 契约 contracts
# =============================================================================
#
# What this teaches:
# • Declares that a type implements one or more 契约 contracts.
# • Related keywords: 类, 契约
#
# Common mistakes:
# • Declaring `类 实现 Implendum` without implementing all required methods — every method signature in the 契约 must have a body in the 类.
#
# See also: 类, 契约
# =============================================================================
# 实现 — 类 implements a 契约 (interface contract)
#
# 类 Nomen 实现 Implendum { … }
#
# GRAMMAR:
# genusDecl :← '类' ident '实现' ident '{' methodDecl* '}'
#
# EXPECTED OUTPUT:
# implet.expected — Aurelia from 契约 plenum().
interface Nominatum {
fn plenum() → string
}
class Civis implements Nominatum {
var string 名称
fn plenum() → string {
# satisfies 契约 requirement
return "§"(self.nomen)
}
}
main {
const Civis civis ← Civis { 名称 = "Aurelia" }
print civis.plenum()
}Expected output:
Aurelia