digitalmars.D - partial class definitions
- Jakob Praher (24/24) Apr 02 2007 hi all,
- Jarrett Billingsley (3/7) Apr 02 2007 Nope.
- janderson (54/91) Apr 02 2007 You could use inheritance:
- Ary Manzana (16/27) Apr 02 2007 Actually, the code above dosen't compile: "parenthesized
- janderson (6/38) Apr 02 2007 Thanks,
hi all, I am new to D. I was wondering wheather D supports some kind of partial class definition, that means one class that is implemented in several translation units? Foo.d: class Foo { XMLNode toXML(); void process() { XMLNode node = this.toXML(); //... } } FooXml.d: class Foo { XMLNode toXML() { //... } } thanks -- Jakob
Apr 02 2007
"Jakob Praher" <jp hapra.at> wrote in message news:euqjjs$2fve$1 digitalmars.com...hi all, I am new to D. I was wondering wheather D supports some kind of partial class definition, that means one class that is implemented in several translation units?Nope.
Apr 02 2007
Jakob Praher wrote:hi all, I am new to D. I was wondering wheather D supports some kind of partial class definition, that means one class that is implemented in several translation units? Foo.d: class Foo { XMLNode toXML(); void process() { XMLNode node = this.toXML(); //... } } FooXml.d: class Foo { XMLNode toXML() { //... } } thanks -- JakobYou could use inheritance: Foo.d: class Foo { abstract XMLNode toXML(); void process() { XMLNode node = this.toXML(); //... } }FooXml.d:class Foo2 : Foo { XMLNode toXML() { //... } } Or you could use mixins: template Part1 { void process() { XMLNode node = this.toXML(); //... } };FooXml.d:class Foo2 { mixin Part1; XMLNode toXML() { //... } } Or you could use a slightly more hacky import: Part1.d void process() { XMLNode node = this.toXML(); //... }FooXml.d:class Foo2 { import("Part1.d"); XMLNode toXML() { //... } } Not quite as tiny as what you request, but close enough in my opinion and they allow better reuse. Of course you probably would give the moduals better logical and reusable names.
Apr 02 2007
janderson escribió:Jakob Praher wrote: Or you could use mixins: template Part1 { void process() { XMLNode node = this.toXML(); //... } };Actually, the code above dosen't compile: "parenthesized TemplateParameterList expected following TemplateIdentifier". So you have to write: template Part1() { void process() { XMLNode node = this.toXML(); //... } }; Is there any reason the parenthesis are mandatory for no-arguments templates? I propose to remove this restriction to allow cleaner syntax for templates that dosen't recieve any parameters.
Apr 02 2007
Ary Manzana wrote:janderson escribió:Thanks, Actually I haven't tested any of the code above. You'll of course need to use import to make the other file available.Jakob Praher wrote: Or you could use mixins: template Part1 { void process() { XMLNode node = this.toXML(); //... } };Actually, the code above dosen't compile: "parenthesized TemplateParameterList expected following TemplateIdentifier". So you have to write: template Part1() { void process() { XMLNode node = this.toXML(); //... } };Is there any reason the parenthesis are mandatory for no-arguments templates? I propose to remove this restriction to allow cleaner syntax for templates that dosen't recieve any parameters.I agree, then it would make switching from classes to templates more generic.
Apr 02 2007