Once Again, Feature Request: Nested classes in separate scope

Vladimir Panteleev thecybershadow at gmail.com
Tue Nov 6 01:53:10 PST 2007


On Tue, 06 Nov 2007 04:48:43 +0200, downs <default_357-line at yahoo.de> wrote:

> 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? :)

I think this could be done with the announced "alias foo this;" syntax.
(just declare a Foo in Bar and import its namespace)

-- 
Best regards,
 Vladimir                          mailto:thecybershadow at gmail.com



More information about the Digitalmars-d mailing list