partial class

Alexander Pánek alexander.panek at brainsware.org
Sat Nov 1 05:14:22 PDT 2008


Ary Borenszweig wrote:
> Mike James escribió:
>> 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...
> 
> Julio's second example convinced me that partial classes are useful. But 
> in D you can already do that, sort of:
> 
> class Foo {
> 
>   // Methods handled by the user
>   void one() { }
>   void two() { }
>   // ...
> 
>   mixin GeneratedFoo!();
> 
> }
> 
> // far, far away
> template GeneratedFoo() {
> 
>   void three() { }
>   void four() { }
> 
> }

You can’t just “monkey-patch” the original class, though. With partial 
classes you could just inject some additional code to the original class.

I don’t think partial classes fit into D. You can do the same thing via 
abstract classes and subclassing without altering the original 
class/interface.



More information about the Digitalmars-d mailing list