[fpc-devel] protected members access across classes in the same package, but what about inherited cross package
Martin Friebe
fpc at mfriebe.de
Sun Jul 20 16:56:51 CEST 2008
Just a question, which came to my mind in relation to
http://bugs.freepascal.org/view.php?id=11697
I understand that if you declare 2 classes in the same package (same
file), then they are allowed to look at each others protected members
(variables, properties, func, proc).
I wonder what the intend or language definition says about inherited
protected members those classes have, if the parent implementation comes
from different files?
Examples:
[file foo.pp]
type
TThat = class(TObject)
protected
ThatValue : integer
end;
TThis = class(TObject)
....
end;
implementation ...
[/end of file foo.pp]
I know it is correct that any code of TThis can access ThatValue.
If you have code in any other package/file (belonging to any other
class) it should not be able to access ThatValue.
[file bar.pp]
type
TThatFake class(TThat)
end; // intntionally empty class
TSomething = class(...)
....
[/end of file bar.pp]]
- If TThatFake had any code, then any code belonging to TThatFake would
be allowed to see it's anchestor protected members, that would be correct.
- If TThatFake had any protected mebers implemented in bar.pp they
should be visble to other code in bar.pp
- But what about inherited members? Should TSomething be able to access
ThatValue?
I do not know the answer, it can be argued both ways. But it allows to
bypass proper encapsulation as seen in the above link.
Best Regards
Martin
More information about the fpc-devel
mailing list