Add a protected keyword for real protected access (instead of the @protected annotation) #1026
Labels
feature
Proposed language feature that solves one or more problems
state-duplicate
This issue or pull request already exists
Hi,
it would be great to have the capability of a real
protected
keyword to manage the visibility of class attributes.By real, I mean by not using the
@protected
annotation. Something like this:The reason I'm asking this is that when we mark something with the
@protected
annotation, it will only be a listing warning, since methods or properties marked with the@protected
annotation will be publicly visible and nothing will stop anyone from using those methods or properties, they'll just have to ignore the linting rule.When marking something as protected I expect it to be visible only to a class and its subclasses, and I'm probably willing to avoid making protected stuff visible to anyone, both for "privacy" and, mostly, to avoid clutter when leveraging the autocomplete feature of the IDE.
As of today, I've found only two ways to have a behaviour similar to a real
protected
keyword.The first one is make the stuff you would like to make
protected
as private and define all the subclasses within the same file (turns out that the Dartprivate
concept has scope in the file and not in the class, it'd be great to have a realprivate
thing too, but that's not the scope of this request): subclasses will see the "private" things and will be able to use them.Another one is using again the "private" as
protected
trick mentioned above, but instead of having all in one file (which might result in a mess), we could use thepart
/part of
directives, which, in the end, is a way to have multiple files treated as one.Is a real
protected
feature possibile?If not, let me ask this: I'm sure you have thought of that when designing the language, why have you dropped the idea of a
protected
concept?The text was updated successfully, but these errors were encountered: