-
Notifications
You must be signed in to change notification settings - Fork 205
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
Alternative type naming for sealed
class subclasses
#4166
Comments
sealed
class subclassessealed
class subclasses
Could be solved with #336. |
Agree. I'd rather have real static nested classes than any aliasing or shorthand. sealed class Animal {
static class Wild extends Animal { ... }
static class Domestic extends Animal { ... }
///
} also allow switch (someAnimal) {
case .Wild(...): ...
case .Domestic(...): ...
...
} |
Also somewhat related to #3021 |
I agree with @nathnaeld that not having to effectively namespace the sealed classes with their supertype name would be nice. But as @lrhn says, I think the best way to get that is through some kind of nested class support like #1183 or #3021. I'm going to go ahead and close this because I don't think this is the specific approach we're likely to take. |
Current Behavior
To maintain clarity, long class names may be used explicitly in the absence of an alternative short naming mechanism.
Proposed Feature
Introduce an alternative naming mechanism for sealed class subclasses, allowing shorter, more intuitive names while retaining the original functionality.
Benefits
Wild
,Domestic
,Aquatic
, andFlying
reduce verbosity and improve code clarity. They also simplify switch statements by eliminating long case names, making the code more concise, easier to read, and maintain without sacrificing clarity.Animal.Wild
), eliminating the need to recall full class names or the inheritance structure, leading to more efficient and less error-prone code.This feature is a quality-of-life improvement that is fully backward-compatible, offering ergonomic enhancements when working with sealed classes, particularly in state management scenarios like Flutter Bloc or other hierarchical structures.
The text was updated successfully, but these errors were encountered: