Newbie OOP question...

G

Guest

Is it correct of me to assume that the design motivation for having a nested class is that the nested class should never be able to be instantiated outside of its parent container

a quick example would be if I were creating a ToolChest object, which would contain a ToolsCollection object, but the ToolsCollection could never be instantiated directly by calling New ToolsCollection(), but would automatically be created by the ToolChest object upon ITS creation..

sidebar... if anyone knows of any really good reading on these types of abstract issues that might be less than obvious to an OOP newbie, that would also be appreciated

Thanks!
 
A

AlexS

Hi, artifact

No, it's not correct. Apart from accessibility, visibility and scoping
nested classes could be useful in complex object models, I would suggest to
check C++ Language Specs for some details, which demonstrate various
aspects. And you can google several other languages, like Java, to check how
the concept is defined there.
Generally
A nested class has access to the variables and methods of the outer class,
even if they are declared private

In certain situations this makes the implementation of the classes easier
because they can easily share information

Furthermore, the nested class can be protected by the outer class from
external use



HTH

Alex

artifact said:
Is it correct of me to assume that the design motivation for having a
nested class is that the nested class should never be able to be
instantiated outside of its parent container?
a quick example would be if I were creating a ToolChest object, which
would contain a ToolsCollection object, but the ToolsCollection could never
be instantiated directly by calling New ToolsCollection(), but would
automatically be created by the ToolChest object upon ITS creation...
sidebar... if anyone knows of any really good reading on these types of
abstract issues that might be less than obvious to an OOP newbie, that would
also be appreciated.
 

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

Similar Threads

OOP Failed? 6
OOP question VB.NET 7
A Newbie OOP conceptual question 2
OOP Inheritance Question 3
OOP or COP? 3
OOP Question 17
OOP Question 2
Size of Common Assembly 1

Top