-
Notifications
You must be signed in to change notification settings - Fork 207
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
Add access modifiers #835
Comments
See fx #757 for proposals on how to add "protected"- and "private"-like features to Dart. Just adding the modifiers won't do anything if we can't integrate it into how the language actually works. Dart currently doesn't even have the concept of private or protected members, so we'd have to add that as well. Dart allows you to dynamic invocation. If you have Dynamic dispatch is one of the things which makes it hard for Dart to implement "private" and "protected" similarly to, fx, Java. We don't always know the type of the object we are calling the method on at compile-time, and doing that kind of checks at run-time can easily become very expensive. The Dart model of having library-private names, so it is impossible to even name a method that you don't have access to, works well with dynamic invocation. |
e.g. by declaring them |
If it can be used to make the distinction at the use-site, where necessary, then sure. If a name is "private", then it should be to everybody else as if it isn't there. Otherwise the privacy is leaking out. One of the primary uses of private names is to avoid conflicts. I think that's more important than avoiding access. |
+1:
|
Well, having |
I just got bitten by this yesterday, because I hadn't thought of that a private property will not be overridden by a deriving class. I don't know if we even have a lint to warn, that a private property is shadowed which could be unintentional. protected properties and potentially a concept of ´friend´ classes would make a lot of design easier while strongly supporting encapsulation and information hiding. |
It would nice to be have private, protected, and public access modifiers added to the language.
The text was updated successfully, but these errors were encountered: