"Ron Lu" <email@example.com> wrote in message news:firstname.lastname@example.org... > "Nick Clark" wrote in message <email@example.com>... >> Hi all, >> I have a query regarding inheritance of one class by another within a >> package. For example, classB < classA within package mypack. From outside >> the package directory I type: >> >> import mypack.* >> x = classB >> >> . . then I get an error saying that classA cannot be accessed. I can >> resolve this by making classB < myclass.classA at the top of the classdef >> of classB. However, this seems like a bit of a clunky 'duct tape' kind of >> work around. It also causes problems when trying to display the >> documentation about the classes which are linked in blue from the disp >> command. >> >> What is the recommended elegant method for inheritance within a package? > > Anyone can help? > > I ran into the exact same problem. > I already finished all my classes and now want to put them into different > packages. And I HAVE TO add those import statements everywhere, or add > packageName.Class* to let the class know where to find dependencies in the > same package.
That is correct.
> Is there a way to work around?
No. Packages define a namespace, and the package name is sort of part of the name of the class.
As a concrete example, if you had this directory structure (with mydirectory on the path):
and you wanted to create an instance of the class defined in the classB.m file inside +myPack from within the classA.m file, you would need to use mypack.classB. If instead you wanted to instantiate an instance of the mydirectory\classB.m class, you would simply use classB. [If you imported mypack.classB inside classA.m, I don't believe you'd be able to access the classB class defined outside the package in the function in which you imported.]