Newbie OOP question...

  • Thread starter Thread starter Guest
  • Start date Start date
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!
 
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.
 
Back
Top