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

[Sealed class] Language feature docs #4581

Closed
Tracked by #51278
itsjustkevin opened this issue Feb 6, 2023 · 0 comments
Closed
Tracked by #51278

[Sealed class] Language feature docs #4581

itsjustkevin opened this issue Feb 6, 2023 · 0 comments
Assignees
Labels
a.language Relates to the Dart language tour co.request Community ask for documentation e1-hours Can complete in < 8 hours of normal, not dedicated, work p2-medium Necessary but not urgent concern. Resolve when possible. st.triage.ltw Indicates Lead Tech Writer has triaged

Comments

@itsjustkevin
Copy link

itsjustkevin commented Feb 6, 2023

Summary

Sealed classes are a class modifier. Declaring a supertype class sealed means it can't be directly extended, implemented, or mixed in from outside their originating library.

From the Class Modifiers spec:

"But it doesn't prevent you from subtyping within the same library. In fact, the whole point of sealed is to define subtypes within the same library so that you can pattern match on those to cover the supertype."

Their motivating use case is exhaustiveness checking, a new feature of switch cases. They are the only class modifier that touch on patterns.

Evaluation

  1. Document semantics with new Class modifiers content. Show how to use (just sealed keyword), show example of sealed superclass and subclasses, and what affect that has on subclasses.

    Content in class modifiers section shouldn't address exhaustiveness checking or patterns, but should link out to that content ("learn more about sealed classes use cases...).

    Class modifiers content might go under the "Libraries" umbrella (side nav), or under the "Classes" section of the "Language" umbrella (see [Class modifiers] Language feature docs #4497)

  2. In exhaustiveness checking content (which will be part of new switch content), link to semantic definition of the sealed class modifier.
    Then, go into detail on how sealed creates a closed hierarchy of classes, how that enables exhaustiveness checking that allows you to switch on object patterns.

  3. IF we get to a point where we're documenting the collection of patterns features that enable functional style, then sealed classes will come up there (but that might be sufficiently covered by the description of exhaustiveness checking and switch)

  4. MAYBE point to sealed content from enum content in language tour.

    Something like "you can enumerate subclasses using the sealed class modifier..."

Resources

@parlough parlough added a.language Relates to the Dart language tour co.request Community ask for documentation p2-medium Necessary but not urgent concern. Resolve when possible. e1-hours Can complete in < 8 hours of normal, not dedicated, work labels Feb 6, 2023
@MaryaBelanger MaryaBelanger self-assigned this Feb 27, 2023
@atsansone atsansone added the st.triage.ltw Indicates Lead Tech Writer has triaged label Apr 12, 2023
MaryaBelanger added a commit that referenced this issue May 8, 2023
- New class modifiers page 
- Minor changes to mixin page
- Added modifiers to Keywords page
- Moved "Abstract classes" section off of "Classes" page and to "Class
modifiers > `abstract`" section

Fixes #4497 
Fixes #4662 
Fixes #4581
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a.language Relates to the Dart language tour co.request Community ask for documentation e1-hours Can complete in < 8 hours of normal, not dedicated, work p2-medium Necessary but not urgent concern. Resolve when possible. st.triage.ltw Indicates Lead Tech Writer has triaged
Projects
None yet
Development

No branches or pull requests

4 participants