--
For other discussions, see https://groups.google.com/a/dartlang.org/
For HOWTO questions, visit http://stackoverflow.com/tags/dart
To file a bug report or feature request, go to http://www.dartbug.com/new
To unsubscribe from this group and stop receiving emails from it, send an email to misc+uns...@dartlang.org.
--
For other discussions, see https://groups.google.com/a/dartlang.org/
For HOWTO questions, visit http://stackoverflow.com/tags/dart
To file a bug report or feature request, go to http://www.dartbug.com/new
To unsubscribe from this group and stop receiving emails from it, send an email to misc+uns...@dartlang.org.
I haven't found a good alternative. The choice I'd go for is to have package private fields and static access methods on the base implementation class. That way subclasses that know that they extend the base class can use the static methods to get access to the private parts, and other code can't see it directly.
I haven't found a good alternative. The choice I'd go for is to have package private fields and static access methods on the base implementation class. That way subclasses that know that they extend the base class can use the static methods to get access to the private parts, and other code can't see it directly.Can you give a small example?
--
For other discussions, see https://groups.google.com/a/dartlang.org/
For HOWTO questions, visit http://stackoverflow.com/tags/dart
To file a bug report or feature request, go to http://www.dartbug.com/new
To unsubscribe from this group and stop receiving emails from it, send an email to misc+uns...@dartlang.org.
I don't really need full, runtime protected fields. The @protected annotation solution (as described here: https://code.google.com/p/dart/issues/detail?id=6119) would be enough.And actually it feels quite Dartish, similar to optional typing: like types, privacy is reduced to a static, compile/development time concern.-g.
What's the problem with introducing the @protected annotation and adding special handling for this in the editor?
"the latter only works if you type annotate everything"That's true of most things isn't it? If you want warnings you need to type annotate things or have the analyser determine the propagated type.Would this be any different?
"the latter only works if you type annotate everything"That's true of most things isn't it?
If you want warnings you need to type annotate things or have the analyser determine the propagated type.Would this be any different?
I have been struggling with this issue a lot at the moment with code that's all within the one package. Basically there is code that I want subclasses to be able to access / override but I don't want objects using the class to have access to.
I seem to be faced with three options
- Massive libraries using 'part of'
- Making things public that shouldn't be
- Duplicating code
None of these are attractive. I have mostly settled for option 3 and trying to limit the duplicated code by factoring the meat of them into reusable helpersAs I am wanting to override code the object based protected approach wouldn't work
@Lasse:Please recall that the complaint was about private members not visible from subclasses. Unless I misunderstand the issue completely (which might happen, of course), there's an obvious solution that doesn't lead to any paradoxes.First, let's observe that the the following definition:someFunc(var x) {x._foobar();}doesn't cause any warning in dart editor, though _foobar is nowhere to be seen in this library at all.However, the absence of warning doesn't mean it will work in runtime, because, according to spec"Any attempt to access a private member declaration from outside L will cause a method, getter or setter lookup failure"And indeed, if we define class X with private method _foobar in a different library, and call someFunc(new X()) - it will fail with noSuchMethod exception.
Keeping that in mind, let's forget the word "protected" - it has some connotations from java which are not relevant here.Let's find another word. Just for the sake of argument, let's name it "@visibleFromSubclasses". When applied to private member, it makes it visible from methods of subclasses ("visible" in a specific sense- see below). When applied to public members, it does nothing at all.Examples:class Base {@visibleFromSubclassesvoid _bar() { ...}}class Derived extends Base {foo() {_bar(); // OK - compiler can prove the access is OKmyClosure() {_bar(); // OK - compiler can prove the access is OK}}}someFunction(var x) {x._bar(); // no warning, but will fail in runtime, like it does now.}The difference is: when compiler can prove by static analysis that, due to annotation, private member is accessible from the point of invocation, it generates special code that prevents checking for the samelibrary in runtime. If it can't prove that, it treats it like access to normal private member, which may cause noSuchMethod in runtime.Does it make sense?
As I am wanting to override code the object based protected approach wouldn't work
It is different from private members, and that is what it is going to be compared to.I can see a real solution, but I'm not convinced that annotations is sufficient.
I have been struggling with this issue a lot at the moment with code that's all within the one package. Basically there is code that I want subclasses to be able to access / override but I don't want objects using the class to have access to.What is the exact problem you are trying to solve?- Cooperating programmers misusing a protected method, i.e., in your own code base? Deliberately or accidentally?
I seem to be faced with three options
- Massive libraries using 'part of'
This doesn't solve the first problem where the misuse is in your own code, if all your code is in one library anyway.
- Making things public that shouldn't be
Again, what is the problem with the method being public?Would it be sufficient to have the public facing library exposing the public interface, and an implementation library with the implementation. Public methods in the implementation that are not in the interface, will cause warnings for any user only importing the public interface versions. Subclasses can do the same thing, only exposing the public interface.
Would it be sufficient to have the public facing library exposing the public interface, and an implementation library with the implementation. Public methods in the implementation that are not in the interface, will cause warnings for any user only importing the public interface versions. Subclasses can do the same thing, only exposing the public interface.
--