For future reference: nested classes and access modifiers (protected, protected internal)

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.
 
J

Jon Skeet [C# MVP]

By writing "if you're a writer", you've made a completely silly
statement. Writers have just as much use for a toothbrush as they do
for a pencil. They don't use the toothbrush for writing (one hopes),
but they still need to brush their teeth.

Ironically, although I'm a writer I use a toothbrush twice a day, but I
can't remember when I last used a pencil :)
 
M

Michael S

Jon Skeet said:
Ironically, although I'm a writer I use a toothbrush twice a day, but I
can't remember when I last used a pencil :)

.... you nerd... :)

- Michael Starberg
 
M

Michael S

Peter:
I have now read this entire thread,
and I admire your patience with this dude.

Also, I had never considered nested classes so much,
even if I use them often. I got all you said, the first time
you explained it. Actually, it worked as one might expect.


raylopes99:
Next time you try to learn something in .NET,
don't start by snorting a full kilogram of amphetamines,
make up how things should work according to you,
and then refuse to stand corrected.

Amusing Thread :)
- Michael Starberg
 
S

Smithers

Peter:
I have now read this entire thread,
and I admire your patience with this dude.

Totally agreed! - Jon and Peter should get some award for their routine
contributions and patience in this NG. Jon is already an MVP - Peter should
be too, IMO.

-S
 
D

Doug Semler

Michael S said:
... you nerd... :)


If he's anything like me...he'd probably prefer "geek" to "nerd" :-D

--
Doug Semler, MCPD
a.a. #705, BAAWA. EAC Guardian of the Horn of the IPU (pbuhh).
The answer is 42; DNRC o-
Gur Hfrarg unf orpbzr fb shyy bs penc gurfr qnlf, abbar rira
erpbtavmrf fvzcyr guvatf yvxr ebg13 nalzber. Fnq, vfa'g vg?
 
D

Doug Semler

Michael S said:
Hehe, geeks uses pencils. :)



Noooo geeks use dry erase markers! :)

--
Doug Semler, MCPD
a.a. #705, BAAWA. EAC Guardian of the Horn of the IPU (pbuhh).
The answer is 42; DNRC o-
Gur Hfrarg unf orpbzr fb shyy bs penc gurfr qnlf, abbar rira
erpbtavmrf fvzcyr guvatf yvxr ebg13 nalzber. Fnq, vfa'g vg?
 
J

judah veichselfish

Hi,
You wrote: The "forward reference" isn't a way, because no such thing exists in C#.
If forward reference does not exist in c#, why the compilation of following piece of code will fail?
a=5;
int a;
Thanks in advance
xyoavx

EggHeadCafe - .NET Developer Portal of Choice
http://www.eggheadcafe.com
 
J

Jon Skeet [C# MVP]

If forward reference does not exist in c#, why the compilation of following piece of code will fail?
a=5;
int a;

Forward references in the context of the discussion are to do with
declaring that methods (or other members) exist in a class or similar
"outer scope" before providing the implementation.

It's not to do with trying to use a *local variable* within a method
before declaring it.

Jon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top