File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to decide whether to use inner class or not

 
Anup Katariya
Greenhorn
Posts: 29
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

In above code, in my case, object1 is meaningless if object2List is null, but independent object2 has also no meaning.
So are they tightly coupled here? or they are just in one java file instead of two?
What are other possibilities, where I would need this kind of thing?
Thanks
Anup
 
Jose Botella
Ranch Hand
Posts: 2120
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch Anup.
I have not got exactly what you are asking, but I will try anyway.
In order to create an instance of the inner class an object of the outer class is needed. The inner instance receives a reference to the outer in its constructor ans uses it to access any of the outer members, even the private ones. Thus I will say that the two instances are tightly coupled.
You can see examples in Thinking in Java
[ November 01, 2002: Message edited by: Jose Botella ]
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic