Summary#
sealed entity Invoice { … } declares that no type may derive from this one. It is C#'s keyword with C#'s
default: a type is open unless sealed.
Sealing is a decision a type makes about itself. It has nothing to do with access — a sealed entity's rows are
read and written exactly as any other's, governed by its security { } block.
Signature#
sealed entity <Name> { <members> }Description#
What does sealed do?#
An attempt to derive from a sealed type is a compile error, naming the sealed type:
sealed entity Invoice { [Required] string Number; }
entity CreditNote : Invoice { … } // ✗ 'Invoice' is `sealed`, so no type may derive from itSeal a type when its shape and its rules are the whole story and a subtype would only blur them — a ledger entry, an audit row, a settled document. Leave it open when deriving is a use you intend to support.
What sealing is NOT — access control, partial, class#
- Sealing is not access control. It does not restrict reading or writing; that is the
security { }block, and a sealed entity takes one exactly as any other does. - Sealing is compatible with
partial.partial entity X { security { … } }states more about this type; sealing refuses a new type. C# treats them as orthogonal for the same reason. (sealedon apartialis refused, though — a partial does not declare the type, so it cannot decide what may derive from it.) - A
classis sealed already, by fact rather than by declaration: nothing can derive from an in-memory value type in Osy#, so writing the word there would say nothing and is refused.
The platform seals its own types#
Every type the platform ships is sealed, with deliberate, reviewed exceptions for the ones you are meant to extend.
So if a platform type takes a : Base clause, that is a commitment rather than an oversight.
Examples#
// Nothing derives from a posted ledger entry — its shape and its rules ARE the record.
sealed entity LedgerEntry {
[Required, MaxLength(40)] string Reference;
[Required] decimal Amount;
}
// A document, on the other hand, is a shape other kinds of document build on.
entity Document {
[Required, MaxLength(200)] string Title;
}
entity Contract : Document {
[Required, MaxLength(80)] string Counterparty;
}See also#
- entity Sub : Base — what deriving actually gives you, and what it refuses
- entity — the
entitydeclaration itself - security { } — who may read and write a type, which sealing does not touch