How to break module into multiple file.

Jonathan M Davis jmdavisProg at gmx.com
Thu May 12 08:05:17 PDT 2011


On 2011-05-12 06:33, Matthew Ong wrote:
> Hi,
> 
> According to:
> http://www.digitalmars.com/pnews/read.php?server=news.digitalmars.com&group
> =digitalmars.D&artnum=135947
> 
> And also source code within dmd2/src
> It seems that there is only one file per module.
> 
> Is module similar to a single java package and namespace in VC++/C#?
> 
> If yes, most name spaced programming language allow breaking of single
> module into multiple
> file to store various logically linked class and separate them when they
> are not.
> 
> Like module Collection may have:
> Common interfaces for both HashMap, LinkedList and hashlist.
> 
> But they should be all be in different source file(HashMap.d, LinkedList.d,
> HashList.d) but
> logically within the same module collection.(Directory)
> How do I do that within D? what is the directory layout of the project?

A module is always one file and only one file. However, a module can 
publically import another module (the default import is private) and then any 
module that imports that module will also import the modules that that module 
publically imports. Just stick public in front of an import to make it public.

Any modules within the same directory are within the same package, so they 
would then share package access if you share the package access modifier, but 
there's no way to impor them as a group. Modules are always imported 
individually. The closest you ever get to being able to import them as a group 
is if you have a module which publically imports other modules, and you import 
that module.

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list