You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The visibility/reference of a Mixin to its host variables can only be achieved through the Protocol (similar to the interface for property access). When the host uses a Mixin, it must satisfy the Protocol property constraints (satisfying the type partial order relationship), and it is one-way, that is Mixin is visible to the properties of the host individually, different mixin attributes are invisible to each other, and the host is invisible to the properties in the mixin.
Mixin can only do merged incremental modification, cannot reassign the existing properties of the host, but can define the properties that the host does not have.
Automatic merging of configuration blocks with the same name in mixins and schemas that use the merge operator :.
The KCL code is
schema Person:
mixin [FullNameMixin]
firstName: str
lastName: str
age: int
id?: int
# protocol specifies what properties the host of the mixin must have
protocol FullNameProtocol:
firstName: str
lastName: str
mixin FullNameMixin for FullNameProtocol:
fullName: str = "{} {}".format(firstName, lastName)
alice = Person {
firstName = "Alice"
lastName = "Green"
age = 10
id = 1
}
The output YAML is
alice:
firstName: AlicelastName: Greenage: 10id: 1fullName: Alice Green
The text was updated successfully, but these errors were encountered:
Enhancement
Semantic
:
.The KCL code is
The output YAML is
The text was updated successfully, but these errors were encountered: