'package' and access from subpackages..

Sergey Gromov snake.scaly at gmail.com
Thu Sep 11 10:17:08 PDT 2008


Don <nospam at nospam.com.au> wrote:
> Sergey Gromov wrote:
> > Jarrett Billingsley <kb3ctd2 at yahoo.com> wrote:
> >> "Sergey Gromov" <snake.scaly at gmail.com> wrote in message 
> >>> Another approach is to have hierarchical packages, which sounds close to
> >>> the concept of nested classes and C++ namespaces. So that inner packages
> >>> have access to anything with package access in all outer packages. But
> >>> how do the outer packages communicate with inner? Inner packages are
> >>> required to have interfaces which are public for some outer packages but
> >>> private for some more outer packages. I cannot see an easy solution
> >>> here.
> >> I was thinking that you would put the more generic stuff towards the top of 
> >> the package hierarchy and the more specialized stuff towards the bottom, so 
> >> that the generic stuff wouldn't actually have to access the specialized 
> >> stuff.  I.e. you would declare interfaces in package.*, but you would 
> >> implement them in package.impl.*. 
> > 
> > Yes, I'd organize packages that way, too. Now you call xml.parse(blah). 
> > The xml.parse() wants to create an instance of 
> > xml.concreteparser.Implementation. That requires Implementation in 
> > xml.concreteparser to be visible to the xml package. So should 
> > Implementation be public?
> 
> No. It should be 'package'.

Let me define the package structure a bit clearer.

There's an xml.parser.Parser class.  It's in module parser, in package 
xml.  There are other modules in package xml as well.

There's an xml.concreteparser.mainmodule.ConcreteParser class. It's in 
concreteparser sub-package in xml package.  There are other modules in 
concreteparser package responsible for the concrete parser 
implementation.

Now xml.parser.Parser wants to create an instance of 
xml.concreteparser.mainmodule.ConcreteParser.  Giving package access to 
ConcreteParser makes it visible to all the modules in concreteparser 
package but not in xml package.

Now I'm all ears.



More information about the Digitalmars-d mailing list