www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - nested classes

reply "Kris" <someidiot earthlink.dot.dot.dot.net> writes:
Thought I'd offer some clarifications regarding nested classes, since I've
been using them quite heavily since early March:

1) nested classes are just like nested functions. You can declare them
pretty much wherever you can declare a variable.

2) nested classes are *not* the same as Java inner classes. The latter
include a reference to the enclosing parent, whilst the former do not. In
Java you have to know the "EnclosingClass.this.method()" incantation to
reach the method of an enclosing class (from a child). In D this simply does
not exist. Instead, you pass the enclosing class as a constructor argument
and reference it in the normal fashion. Note that many nested classes do not
need to reference the parent at all ...

3) nested classes are perfectly visible to the outside world. If you have a
nested class Bar within enclosing class Foo, a simple Foo.Bar gives you the
nested class. That is, new Foo.Bar(); is legitimate syntax. Such talk of
"super private" is both badly misguided and misleading.

4) nested classed are the business! As are nested functions. Nice work
Walter.
Jun 03 2004
next sibling parent Arcane Jill <Arcane_member pathlink.com> writes:
In article <c9o7b0$12g0$1 digitaldaemon.com>, Kris says...

3) nested classes are perfectly visible to the outside world. If you have a
nested class Bar within enclosing class Foo, a simple Foo.Bar gives you the
nested class. That is, new Foo.Bar(); is legitimate syntax. Such talk of
"super private" is both badly misguided and misleading.
I didn't think of that. <embarrassed!> Jill
Jun 03 2004
prev sibling next sibling parent "Kris" <someidiot earthlink.dot.dot.dot.net> writes:
I forgot to mention that there's an outstanding bug related to nested static
constructors. See the bug NG for details.


"Kris" <someidiot earthlink.dot.dot.dot.net> wrote in message
news:c9o7b0$12g0$1 digitaldaemon.com...
 Thought I'd offer some clarifications regarding nested classes, since I've
 been using them quite heavily since early March:

 1) nested classes are just like nested functions. You can declare them
 pretty much wherever you can declare a variable.

 2) nested classes are *not* the same as Java inner classes. The latter
 include a reference to the enclosing parent, whilst the former do not. In
 Java you have to know the "EnclosingClass.this.method()" incantation to
 reach the method of an enclosing class (from a child). In D this simply
does
 not exist. Instead, you pass the enclosing class as a constructor argument
 and reference it in the normal fashion. Note that many nested classes do
not
 need to reference the parent at all ...

 3) nested classes are perfectly visible to the outside world. If you have
a
 nested class Bar within enclosing class Foo, a simple Foo.Bar gives you
the
 nested class. That is, new Foo.Bar(); is legitimate syntax. Such talk of
 "super private" is both badly misguided and misleading.

 4) nested classed are the business! As are nested functions. Nice work
 Walter.
Jun 03 2004
prev sibling next sibling parent reply "Blandger" <zeroman prominvest.com.ua> writes:
Thanks Kris for such a clarification!
I think it should be placed to Wiki.

"Kris" <someidiot earthlink.dot.dot.dot.net> wrote in message
news:c9o7b0$12g0$1 digitaldaemon.com...
 Thought I'd offer some clarifications regarding nested classes, since I've
 been using them quite heavily since early March:
Jun 04 2004
parent "Kris" <someidiot earthlink.dot.dot.dot.net> writes:
No sweat Blanger; upload it if you like ...

"Blandger" <zeroman prominvest.com.ua> wrote in message
news:c9pdtq$2rj1$1 digitaldaemon.com...
 Thanks Kris for such a clarification!
 I think it should be placed to Wiki.

 "Kris" <someidiot earthlink.dot.dot.dot.net> wrote in message
 news:c9o7b0$12g0$1 digitaldaemon.com...
 Thought I'd offer some clarifications regarding nested classes, since
I've
 been using them quite heavily since early March:
Jun 04 2004
prev sibling parent "Phill" <phill pacific.net.au> writes:
"Kris" <someidiot earthlink.dot.dot.dot.net> wrote in message
news:c9o7b0$12g0$1 digitaldaemon.com...
 Thought I'd offer some clarifications regarding nested classes, since I've
 been using them quite heavily since early March:

 1) nested classes are just like nested functions. You can declare them
 pretty much wherever you can declare a variable.

 2) nested classes are *not* the same as Java inner classes.
But D's nested classes are the same as Java's nested classes.
Jun 05 2004