• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Real time application of Inner Class

 
Parameswaran Thangavel
Ranch Hand
Posts: 485
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
i need a real time application or implementation to understand the property of inner class. i read and got the semantics of inner class by using MyOuterClass and MyInnerClass. But i need some real time scenario where we can implement Inner Class to represent that Entity.
 
Joe Ess
Bartender
Posts: 9280
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you mean "real time" as in real-time computing or "real world", meaning a concrete example?
If you mean the latter, I once used an inner class to implement a linked list. Linked lists are made up of node which contain a data reference and pointers to other nodes in the list. Since the user of the linked list is interested in the data in the list and not the implementation of the list itself, I made the node class an inner class.
 
Parameswaran Thangavel
Ranch Hand
Posts: 485
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi joe i am meant to say real world.

can i say that the output of certain process will be a member of the outer class and the thing or logic which brings out will be a inner class..
 
Joe Ess
Bartender
Posts: 9280
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can declare anything to be an inner class. The question remains: should it BE an inner class? I think you have to clear up the relationship between your classes before you can answer that. Have a look at the Java Tutorial chapter on Nested Classes for some more examples.
 
Emanuel Kadziela
Ranch Hand
Posts: 187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You would use an inner class only if you are dealing with an object that has no use or meaning outside of its outer class and is complex enough to merit its own objectification (for a lack of a better term). It's difficult to find a general example because it really depends on your application, but perhaps an Address class could have a PhoneNumbers inner class which holds all the phone numbers associated with the address and implements some extra functionality, like returning the best phone number, the most used one and whether they are all in the same area code. You need a class to do all the extra nifty things, but you don't really need it in a separate class, since you do not need (or want) to deal with phone numbers outside of the context of an Address.
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic