# sealed

> Declares that no type may derive from this entity. A type is open unless it says otherwise, exactly as in C#. Sealing says nothing about who may read or write the type.

<!-- id: entity-sealed · area: entity · stability: stable · html: https://osysharp.com/reference/entity/sealed/ -->

## Summary        {#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      {#signature}
```osy syntax
sealed entity <Name> { <members> }
```

## Description    {#description}

### What does `sealed` do?                        {#what}
An attempt to derive from a sealed type is a compile error, naming the sealed type:

```osy syntax
sealed entity Invoice { [Required] string Number; }
entity CreditNote : Invoice { … }   // ✗ 'Invoice' is `sealed`, so no type may derive from it
```

Seal 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`  {#orthogonal}

- **Sealing is not access control.** It does not restrict reading or writing; that is the [`security { }`](https://osysharp.com/reference/security/entity-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. (`sealed` **on** a `partial` is refused, though — a partial does not declare the type, so it cannot decide what may derive from it.)
- **A `class` is 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     {#platform}
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       {#examples}

```osy title="a settled document, and an open one" test app=entity-sealed
// 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       {#see-also}
- [entity Sub : Base](https://osysharp.com/reference/entity/inheritance/) — what deriving actually gives you, and what it refuses
- [entity](https://osysharp.com/reference/entity/declaration/) — the `entity` declaration itself
- [security { }](https://osysharp.com/reference/security/entity-security/) — who may read and write a type, which sealing does not touch
