www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Split D class file

reply B.Schulte <Aldioric gmx.de> writes:
Hi!

Is it somehow possible to store some methods of a class in another D file? The
class is really getting too big.

Well, maybe some of you suggest me to split the class in multiple ones, but
this class is important to be one part. The only way would be to have many many
friend classes. But that's also very strange.
Sep 22 2007
next sibling parent reply BLS <nanali nospam-wanadoo.fr> writes:
B.Schulte schrieb:
 Hi!
 
 Is it somehow possible to store some methods of a class in another D file? The
class is really getting too big.
 
 Well, maybe some of you suggest me to split the class in multiple ones, but
this class is important to be one part. The only way would be to have many many
friend classes. But that's also very strange.

Bjoern
Sep 22 2007
parent reply redsea <redsea gmail.com> writes:
code coverage report can not support mixin template :(

BLS Wrote:

 B.Schulte schrieb:
 Hi!
 
 Is it somehow possible to store some methods of a class in another D file? The
class is really getting too big.
 
 Well, maybe some of you suggest me to split the class in multiple ones, but
this class is important to be one part. The only way would be to have many many
friend classes. But that's also very strange.

Bjoern

Sep 22 2007
parent BLS <nanali nospam-wanadoo.fr> writes:
redsea schrieb:
 code coverage report can not support mixin template :(

Well that's not a big deal IMO. In case that it is "mission critical" write adequate intermediate functions instead. Or do I miss something ?
 
 BLS Wrote:
 
 B.Schulte schrieb:
 Hi!

 Is it somehow possible to store some methods of a class in another D file? The
class is really getting too big.

 Well, maybe some of you suggest me to split the class in multiple ones, but
this class is important to be one part. The only way would be to have many many
friend classes. But that's also very strange.

Bjoern


Sep 23 2007
prev sibling next sibling parent reply Jari-Matti =?ISO-8859-1?Q?M=E4kel=E4?= <jmjmak utu.fi.invalid> writes:
B.Schulte wrote:

 Hi!
 
 Is it somehow possible to store some methods of a class in another D file?
 The class is really getting too big.
 
 Well, maybe some of you suggest me to split the class in multiple ones,
 but this class is important to be one part. The only way would be to have
 many many friend classes. But that's also very strange.

Inheritance, composition and mixins are quite common design patterns in OO languages. D also has hybrid member/free functions. If none of those help, you probably have a major problem in the program design.
Sep 23 2007
parent BLS <nanali nospam-wanadoo.fr> writes:
Jari-Matti Mäkelä schrieb:
 B.Schulte wrote:
 
 Hi!

 Is it somehow possible to store some methods of a class in another D file?
 The class is really getting too big.

 Well, maybe some of you suggest me to split the class in multiple ones,
 but this class is important to be one part. The only way would be to have
 many many friend classes. But that's also very strange.

Inheritance, composition and mixins are quite common design patterns in OO languages. D also has hybrid member/free functions.

 you probably have a major problem in the program design.

Was my first idea too. Means having a fat class is more an design issue than an language related prob. But since I am going to translate a MFC like GUI using a lot of GDI wrapper functions I am not that sure. ;-) Bjoern....
Sep 23 2007
prev sibling next sibling parent Chad J <gamerChad _spamIsBad_gmail.com> writes:
B.Schulte wrote:
 Hi!
 
 Is it somehow possible to store some methods of a class in another D file? The
class is really getting too big.
 
 Well, maybe some of you suggest me to split the class in multiple ones, but
this class is important to be one part. The only way would be to have many many
friend classes. But that's also very strange.

Just to make sure it's clear, here's how it's done with mixins: // file 1, main.d or whatever import std.stdio; import second; void main() { Big biggy = new Big(); } class Big { this() { writefln(getDescription()); } mixin BigPeice!(); // getDescription() ends up defined here. } // file 2, second.d template BigPeice() { char[] getDescription() { return "Big is a hypothetically very big class and must be split."; } }
Sep 23 2007
prev sibling parent =?ISO-8859-1?Q?Julio_C=E9sar_Carrascal_Urquijo?= writes:
Hi

B.Schulte wrote:
 Hi!
 
 Is it somehow possible to store some methods of a class in another D file? The
class is really getting too big.
 
 Well, maybe some of you suggest me to split the class in multiple ones, but
this class is important to be one part. The only way would be to have many many
friend classes. But that's also very strange.

I think you need Partial Class Definition. It has been requested before but hasn't got much traction: http://www.digitalmars.com/d/archives/digitalmars/D/14513.html http://www.digitalmars.com/d/archives/digitalmars/D/Partial_class_implementation_55745.html I think it's a very useful feature for external code generators. For example: * GUI code generated by a form designer stored in a Form.designer.d file. * Record structures generated from official specs (Something I've personally dealt with in C# and CodeSmith and partial classes did wonders). * Model classes generated from a Database Schema. Very useful when the schema changes and you have to update your database. * etc... I would really love to hear how difficult it would be to implement on DMD or GDC because I really have no idea. Adding it to the language is another matter. Cheers. -- Julio César Carrascal Urquijo http://jcesar.totumo.net/
Sep 24 2007