partial class

Denis Koroskin 2korden at gmail.com
Fri Oct 31 10:33:40 PDT 2008


On Fri, 31 Oct 2008 20:06:42 +0300, KennyTM~ <kennytm at gmail.com> wrote:

> Denis Koroskin wrote:
>> On Fri, 31 Oct 2008 17:37:42 +0300, Mike James <foo at bar.com> wrote:
>>
>>> Not sure if this has been suggested before as an addition to D but  
>>> what about introducing a partial class as per C# - with all the  
>>> benefits it would bring...
>>>
>>> -=mike=-
>>   I must be missing something, but D already supports defining class  
>> methods in one file and implementing them in another one.
>
> Something like this:
>
>
> partial class A {
>      int someMember;
>      public A(int x) { someMember = x; }
> }
>
> // Far, far apart
>
> partial class A {
>      public int getSomeMember() { return someMember; }
> }
>
>
> class X {
>      static void Main() {
>          var someA = new A(12);
>          System.Console.WriteLine(someA.getSomeMember());
>      }
> }

Is this worth the trouble? You can have

class A {
     int someMember;
     public A(int x) { someMember = x; }
     public int getSomeMember();
}

in one module and implement getSomeMember() in another module. I believe  
all the class methods should be defined in one place so that user don't  
need to import class definition from multiple places. This also makes  
semantic analysis more complex.



More information about the Digitalmars-d mailing list