How to break module into multiple file.

Nick Sabalausky a at a.a
Thu May 12 13:11:01 PDT 2011


"Matthew Ong" <ongbp at yahoo.com> wrote in message 
news:iqgnj9$2n0j$1 at digitalmars.com...
> 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?
>

--- Convert this... ---

// libfoo.d
module libfoo;
void a() {}
void b() {}
void c() {}

// main.d
import libfoo;
void main()
{
    a();
    b();
    c();
}

-- ...to this: ---

// libfoo/all.d
module libfoo.all;
public import libfoo.partA;
public import libfoo.partB;
public import libfoo.partC;

// libfoo/partA.d
module libfoo.partA;
void a() {}

// libfoo/partB.d
module libfoo.partB;
void b() {}

// libfoo/partC.d
module libfoo.partC;
void c() {}

// main.d
import libfoo.all;
void main()
{
    a();
    b();
    c();
}




More information about the Digitalmars-d-learn mailing list