Split D class file

Chad J gamerChad at _spamIsBad_gmail.com
Sun Sep 23 19:28:37 PDT 2007


B.Schulte wrote:
> Hi!
> 
> Is it somehow possible to store some methods of a class in another D file? The class is really getting too big.
> 
> Well, maybe some of you suggest me to split the class in multiple ones, but this class is important to be one part. The only way would be to have many many friend classes. But that's also very strange.

Just to make sure it's clear, here's how it's done with mixins:

// file 1, main.d or whatever
import std.stdio;
import second;

void main()
{
   Big biggy = new Big();
}

class Big
{
   this()
   {
     writefln(getDescription());
   }

   mixin BigPeice!(); // getDescription() ends up defined here.
}

// file 2, second.d

template BigPeice()
{
   char[] getDescription()
   {
     return "Big is a hypothetically very big class and must be split.";
   }
}



More information about the Digitalmars-d mailing list