Re: Understanding class access



André Wagner <andre.nho@xxxxxxxxx> wrote:
let's say I'm writing a extension organized in packages such as:

mycompany.mypackage.MyClass
mycompany.mypackage.subpackage.MySubClass


Is there anyway that I can access MySubClass from MyClass, but make
MySubClass invisible for packages outside mycompany.mypackage?

No, because in fact, though the names look herarchical, your
mycompany.mypackage.subpackage is outside of mycompany.mypackage. (As a
side note, if MySubClass is a subclass of MyClass, then trying to access
MySubClass from MyClass is a cyclic dependency anyway.)

It's hard to suggest more than that without knowing why you don't want
anyone outside of mycompany.mypackage to access MySubClass. Is it
simply an organizational principle? If so, then you'll notice a lot of
packages in the standard librari have "implementation" or "provider"
subpackages, and just rely on documentation to say that others shouldn't
use it. If it's a security issue, such as when running untrusted code
in the VM, then you'll have to redesign a bit more than that.

--
Chris Smith
.



Relevant Pages

  • nested classes, OOP
    ... Is there a way to implement nested classes in MATLAB? ... if I have two separate classes "myClass" and ... function = mySubClass() ... but this violates the philosophy of encapsulation. ...
    (comp.soft-sys.matlab)
  • Re: Understanding class access
    ... The people who are going to use my extension will extend MyClass. ... declare it to be public. ... But I want MyClass to be able to access MySubClass, ... MySubClass invisible for packages outside mycompany.mypackage? ...
    (comp.lang.java.programmer)
  • Re: Understanding class access
    ... The people who are going to use my extension will extend MyClass. ... declare it to be public. ... But I want MyClass to be able to access MySubClass, ... MySubClass invisible for packages outside mycompany.mypackage? ...
    (comp.lang.java.programmer)
  • Help! Reflection object target in c#?
    ... public class MySubClass ... public String Text ... public class MyClass ... private MySubClass obj_MySubClass=new MySubClass; ...
    (microsoft.public.dotnet.framework)
  • Re: How to call the subclasss method?
    ... If the method is unique to the subclass you may not want it virtual as other ... > I created a class "myClass" and another class "mySubclass" which inherited ... > but I got an error message when I tried to compile it: ...
    (microsoft.public.dotnet.languages.csharp)