August 07, 2003
"Matthew Wilson" <matthew@stlsoft.org> wrote in message news:bgs4et$1s2p$1@digitaldaemon.com...
> Can we not have both?
>
> I've found nested classes very useful in C++, essential in many ways to enforce design decisions and control users of one's classes.
>
> I've found inner classes very useful in Java (along with those groovy
> anonymous gizmos)
>
> Let's have both in D!
>
> "Sean L. Palmer" <palmer.sean@verizon.net> wrote in message news:bgrcff$1563$1@digitaldaemon.com...
> > I've so often wished I could do that.
> >
> > I'd like to see some kind of inner class support as well.
> >
> > Sean

I though we'd been through this b4, and Walter was totally against inner classes, becuase inner functions as delgates can (in many places) replace them.

however if we're back on that, I too vote for inner classes akin to Java,
they are more robust than inner functions as delegates (and infact you could
make a delegate of a fuction of an anon innerclass that was a shallow copy
of the inner functions stack frame, thus full closures).
I would like to see one addition to inner classes, that of allowing an inner
class to be subclassed without having to subclass the outer class.
as in

class Base {
    inner class Item { // I've used inner here as in Java it would be class,
but in D class means Java static class
            ...
    }
}

in Java to have a subclass of Base.Item
you need to do
class Derived : Base {
    inner class MyItem : Base.Item {
    }
}
because MyItem needs an instance of Base to be connected to;
I would like to see

class MyItem : Item.Base { // assumes that MyItem is connected to a Base }

to create an instance of a MyClass use something like
Base b = new Base();
MyItem ii = b.new MyItem();

or even
class Derived : Base {
}

Derived d = new Derived();
MyItem ii = d.new MyItem();





1 2
Next ›   Last »