partial class

Brian digitalmars at brianguertin.com
Fri Oct 31 10:34:10 PDT 2008


On Sat, 01 Nov 2008 01:06:42 +0800, KennyTM~ 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());
>      }
> }

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

// Far, far apart

class B : A {
     public int getSomeMember() { return someMember; }
}


void main() {
	auto someA = new B;
	someA.init(12);
	writefln(someA.getSomeMember());
}


// Partial class don't seem useful to me. It seems to me they would 
create more problems then they could solve.



More information about the Digitalmars-d mailing list