partial class

KennyTM~ kennytm at gmail.com
Fri Oct 31 13:13:36 PDT 2008


ore-sama wrote:
> KennyTM~ Wrote:
> 
>> Right. It may be useful when you want to provide additional function, 
>> e.g. a getRandom method to a NormalDistribution class where normally 
>> that function would not be needed.
>>
>>    module math.normaldistrib;
>>
>>    partial class NormalDistribution : IDistribution {
>>      double mean() { ... }
>>      double stdev() { ... }
>>      // etc.
>>    }
>>
>> in another module:
>>
>>    module random.normal;
>>
>>    partial class NormalDistribution : IRandomGenerator {
>>      double getRandom() {
>>        // complete something the math. package's author
>>        // don't bother to do.
>>        ...
>>      }
>>    }
> I thought, partial classes work in a different way. So that after compilation partial class is no more partial and considering dmd's way 1 source -> 1 obj it's hard to separate class into 2 source files.

In fact in C# all partial classes must be compiled to the same assembly 
(ref: http://msdn.microsoft.com/en-us/library/wa80x488(VS.80).aspx):

"All partial-type definitions meant to be parts of the same type must be 
defined in the same assembly and the same module (.exe or .dll file). 
Partial definitions cannot span multiple modules."

So yes, after compiling they are no longer partial. You may say you have 
the freedom to choose which part you really want to include in your 
program, which has no much benefit than subclassing it.

In DMD it can work when you cat several sources together. :P



More information about the Digitalmars-d mailing list