J
Jon Skeet [C# MVP]
raylopez99 said:Not a "complete" red herring--not a red herring at all. Just an
observation. Use precise language Jon--that way we can communicate
better, remember? ;-)
No, it *is* a red herring - they're used for different purposes, so
shouldn't be compared. It's like saying, "Inheritance is a pain, and
method calls are better".
Your first reason I've already stated. Your second reason is very
lame IMO--you can communicate much better using a comment-- /// in XML
format.
There are advantages in making the class nested in terms of
intellisense, however. Suppose you needed 5 classes in a namespace,
each of which also needed 2 classes just for use with that one. 15
classes in total. Using top level classes, Intellisense would show you
all 15 each time. Using nested classes, it's more obvious when reading
the code (without needing to consult documentation) that the nested
class is directly related to its enclosing class, and Intellisense will
help you pick the right context - when you're not dealing with the
enclosing class, the nested class won't be offered.
Bottom line is that I doubt I use nested classes much more, any more
than I use Enums for example (int enums, since byte enums are handy as
flags).
Nested classes are useful. Enums are useful. (Enums could be more
useful if they had more of an OO feel, but I digress.) Neither should
be abandoned, and neither is a "pain". The "problems" you've shown in
this thread are problems with your understanding, *not* problems with
nested classes themselves.
What completely confused me with nested classes is that I did
not realize they are instantiated just like any two independent
classes--or a composite class (Class A having as a member a class B)--
I assumed nested classes were like base class inherietance--big
mistake.
Yes, that's a mistake. But having realised that mistake (and having had
it pointed out to you) you should understand that they are *not* a
pain. Anything can be a pain when you don't understand it.