Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

document the sealed feature #194

Merged
merged 3 commits into from
Oct 28, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 36 additions & 1 deletion docs/06-concepts/19-experimental.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ The current options you can pass are:

Inheritance allows you to define class hierarchies in your model files by sharing fields between parent and child classes, simplifying class structures and promoting consistency by avoiding duplicate field definitions.
BenAuerDev marked this conversation as resolved.
Show resolved Hide resolved

### Extending a Class

To inherit from a class, use the `extends` keyword in your model files, as shown below:

```yaml
class: ParentClass
fields:
Expand All @@ -46,6 +50,37 @@ class ChildClass extends ParentClass {
}
```

### Sealed Classes

In addition to the `extends` keyword, you can also use the `sealed` keyword to create sealed class hierarchies. A sealed class restricts which other classes can extend or implement it, allowing for more controlled inheritance. For example:
BenAuerDev marked this conversation as resolved.
Show resolved Hide resolved

```yaml
class: ParentClass
sealed: true
fields:
name: String
```

```yaml
class: ChildClass
extends: ParentClass
fields:
age: int
```

This will generate the following classes:

```dart
sealed class ParentClass {
String name;
}

class ChildClass extends ParentClass {
String name;
int age;
}
```

:::info
The `extends` keyword does not work for models with a `table` field.
All files in a sealed hierarchy need to be located in the same sub directory.
BenAuerDev marked this conversation as resolved.
Show resolved Hide resolved
:::
Loading