Thread overview
Partial classes
Jan 29, 2012
Mars
Jan 29, 2012
bearophile
Jan 30, 2012
Jonathan M Davis
Jan 30, 2012
bls
Jan 31, 2012
Mars
Jan 31, 2012
Jonathan M Davis
Jan 31, 2012
bearophile
Jan 31, 2012
Mars
January 29, 2012
Hello everybody.
Quick question, is there anything like C#'s partial classes in D?

Mars
January 29, 2012
Mars:

> Hello everybody.
> Quick question, is there anything like C#'s partial classes in D?

In D there are ways to compose classes, using static methods of interfaces, with "alias this", and even low-level ways like mixin(import("filename.d")), and so on. But currently there are no partial classes in D. Maybe partial classes will be added in future if their usefulness becomes evident :-)

Bye,
bearophile
January 30, 2012
On Sunday, January 29, 2012 22:43:26 Mars wrote:
> Hello everybody.
> Quick question, is there anything like C#'s partial classes in D?

Not really, no. It's one file per module by design. However, you can use template and string mixins to add code from other files.

- Jonathan M Davis
January 30, 2012
On 01/29/2012 01:43 PM, Mars wrote:
> Hello everybody.
> Quick question, is there anything like C#'s partial classes in D?
>
> Mars

As already said template mixins are close to partial classes.
A snippet. HTH

import std.stdio, std.cstream;

void main(string[] args)
{
	auto bar = new Bar();
	writeln(bar.onClick());

	// Lets the user press <Return> before program stops
	din.getc();
}

mixin template FooMixin()
{
	void initCommonControls()
	{
		
	}
	string onClick()
	{
		return "Clicked";
	}
}

class Foo
{
	mixin FooMixin;
}
class Bar : Foo
{
	
}
January 31, 2012
On Monday, 30 January 2012 at 10:21:07 UTC, bls wrote:
> As already said template mixins are close to partial classes.
> A snippet. HTH
Thanks everybody. I still hope support for partial classes may come some day, to make this cleaner, but I guess it works.
January 31, 2012
On Tuesday, January 31, 2012 11:37:24 Mars wrote:
> On Monday, 30 January 2012 at 10:21:07 UTC, bls wrote:
> > As already said template mixins are close to partial classes. A snippet. HTH
> 
> Thanks everybody. I still hope support for partial classes may come some day, to make this cleaner, but I guess it works.

Well, you can hope, but Walter is very much against the idea, so someone would have to have a very compelling argument to change his mind, and I don't expect that that will happen. The one file per module rule is viewed as too desirable to allow for something like partial classes where you're specifically splitting a module across files.

- Jonathan M Davis
January 31, 2012
Mars:

> Thanks everybody. I still hope support for partial classes may come some day, to make this cleaner, but I guess it works.

Generally it's not wise to go too much against the style of a language. What do you need partial classes for?

Bye,
bearophile
January 31, 2012
On Tuesday, 31 January 2012 at 12:33:22 UTC, bearophile wrote:
> Mars:
>
>> Thanks everybody. I still hope support for partial classes may come some day, to make this cleaner, but I guess it works.
>
> Generally it's not wise to go too much against the style of a language. What do you need partial classes for?
>
> Bye,
> bearophile

"Need"? Nobody "needs" a feature that's basicly only cosmetic. In some cases it makes the files cleaner, as you can split big classes into several files. I just like that^^

Mars