Once Again, Feature Request: Nested classes in separate scope

downs default_357-line at yahoo.de
Mon Nov 5 18:48:43 PST 2007


Needed: a way to add a nested class to some other class without the
nested class having to be inside the scope of the outer class.

I believe this to be important, because it would let us express the
relation of "belongs-to", forming the symmetric opposite of "has-a".

It came up in the context of user interfaces, where every Window
belongs-to a WindowManager. And yes, I know you can give the Window
class a reference to the WindowManager that controls it, but that feels
unclean. It's like, "The WindowManager has many Windows, and each Window
has the original WindowManager". The relations are screwed up.

Syntax proposal (just an idea):

class Foo {
	int e; this() { e=4; }
}

class Bar in Foo : Object {
	void test() { writefln(e); }
}

void main() {
	auto foo=new Foo;
	auto bar=foo.new Bar; // behaves like a nested class
	bar.test(); // prints 4
}

Whaddya think? :)
 --downs



More information about the Digitalmars-d mailing list