-
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 protected. #2571
Comments
You can use I think adding a true language feature for this gets complicated due to dynamic invocations (do you add a runtime check? how much additional info do you have to encode in shipped binaries to support that check?). |
The thing that make it hard is indeed dynamic invocation. And everything having interfaces. Dart does not have an access model that statically checks if you are allowed to call a member. If you can name it, you can call it. Library private members are designed such that you cannot name them from outside the library. It's possible to do something similar to protected in Dart, but it won't be precisely the same as in, say, Java. In Java, the member is accessible on the class type to any code in a class extending the declaring class. In Dart, the members of a class is the same as the members of its interface, we don't have separate names for the two. So we can't distinguish types extending a class from those implementing it, all types are interface types. What I'd do instead is to allow: protected memberDecl; to declare a member which exist only on the class, and is not available in the interface. It's also not available for dynamic invocation. The only way to actually invoke the member is to call it as a member of class Foo {
protected int x = 0;
}
class Bar extends Foo {
// "inherits" protected x.
void inc() {
this.x++;
}
} Subclasses can override the member normally, and access it. To everybody else, the interface of Then it gest complicated. Can a subclass make a non-protected member with the same name? (Maybe.) |
I truly hate the fact that an object or whatever is showen outside of the surrounding directory. It's just so irritating. I only use dart because of flutter. In order to implement an architecture that makes sense. This feature is so necessary, I'm so tired of having to write 500-1000 lines in one single file inorder to eliminate confusion. |
I like Especially if you're just making your own Flutter code and not publishing a package -- what's so wrong with having some extra members exposed to your other code? If you want to be clear about usage, use |
What does this have to do with protected? It sounds like you are expecting Dart to just work exactly like whatever language you are used to (Java?), but it is a different language and likely has a different solution for what you are trying to do. I would suggest using mostly private libraries (under lib/src) and then exporting the types you actually want exposed through a public library. But it is hard to understand exactly what you are looking for here. Dart does not arbitrarily show symbols from entire directories. |
There are times when you want to provide a base class with functionality intended for subclasses, but where that functionality should not be part of the public API that the subclasses expose. There are workarounds to support that in Dart, but none as direct as |
Please add protected. This feature is killing me. It's so necessary.
The text was updated successfully, but these errors were encountered: